Comparing version 2.3.0 to 2.4.0
@@ -15,3 +15,3 @@ function next (middlewares, req, res, index, routers = {}, defaultRoute, errorHandler) { | ||
} else { | ||
return next(middlewares, req, res, ++index, routers, defaultRoute, errorHandler) | ||
return next(middlewares, req, res, index + 1, routers, defaultRoute, errorHandler) | ||
} | ||
@@ -30,2 +30,3 @@ } | ||
} | ||
return middleware.lookup(req, res, step) | ||
@@ -32,0 +33,0 @@ } else { |
@@ -50,5 +50,5 @@ const Trouter = require('trouter') | ||
} | ||
const varsIndex = req.url.indexOf('?') | ||
if (varsIndex > 0) { | ||
req.path = req.url.slice(0, varsIndex) | ||
const qsIndex = req.url.indexOf('?') | ||
if (qsIndex > 0) { | ||
req.path = req.url.slice(0, qsIndex) | ||
} else { | ||
@@ -85,3 +85,2 @@ req.path = req.url | ||
// middlewares invocation | ||
if (!req.params) { | ||
@@ -88,0 +87,0 @@ req.params = {} |
const uWS = require('uWebSockets.js') | ||
const { Writable } = require('stream') | ||
const REQUEST_EVENT = 'request' | ||
@@ -77,3 +78,2 @@ | ||
const q = uRequest.getQuery() | ||
const uRequestKeys = Object.keys(uRequest) | ||
this.req = uRequest | ||
@@ -85,5 +85,5 @@ this.url = uRequest.getUrl() + (q ? '?' + q : '') | ||
for (let i = 0, len = uRequestKeys.length; i < len; i++) { | ||
this.headers[uRequestKeys[i]] = uRequest[uRequestKeys[i]] | ||
} | ||
uRequest.forEach((header, value) => { | ||
this.headers[header] = value | ||
}) | ||
} | ||
@@ -96,4 +96,6 @@ | ||
class HttpResponse { | ||
class HttpResponse extends Writable { | ||
constructor (uResponse, uServer) { | ||
super() | ||
this.res = uResponse | ||
@@ -107,2 +109,7 @@ this.server = uServer | ||
this.headersSent = false | ||
this.on('pipe', _ => { | ||
this.__isWritable = true | ||
this.__writeAllHeaders() | ||
}) | ||
} | ||
@@ -134,15 +141,23 @@ | ||
end (data = '') { | ||
__writeAllHeaders () { | ||
this.res.writeHeader('Date', this.server._date) | ||
const headerKeys = Object.keys(this.headers) | ||
const length = headerKeys.length | ||
for (let index = 0; index < length; index++) { | ||
const key = headerKeys[index] | ||
this.res.writeHeader(key, this.headers[key]) | ||
} | ||
this.headersSent = true | ||
} | ||
end (data = '') { | ||
this.res.writeStatus(`${this.statusCode} ${this.statusMessage}`) | ||
this.res.writeHeader('Date', this.server._date) | ||
for (let i = 0, len = headerKeys.length; i < len; i++) { | ||
this.res.writeHeader(headerKeys[i], this.headers[headerKeys[i]]) | ||
if (!this.__isWritable) { | ||
this.__writeAllHeaders() | ||
} | ||
this.headersSent = true | ||
this.finished = true | ||
this.res.end(data) | ||
@@ -149,0 +164,0 @@ } |
{ | ||
"name": "0http", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "Cero friction HTTP request router. The need for speed!", | ||
@@ -32,8 +32,8 @@ "main": "index.js", | ||
"chai": "^4.2.0", | ||
"find-my-way": "^2.2.2", | ||
"find-my-way": "^2.2.3", | ||
"mocha": "^6.2.3", | ||
"nyc": "^15.0.1", | ||
"standard": "^14.3.3", | ||
"standard": "^14.3.4", | ||
"supertest": "^4.0.2", | ||
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v16.4.0" | ||
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v17.5.0" | ||
}, | ||
@@ -40,0 +40,0 @@ "files": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15170
261