ultimate-express 1.3.10 → 1.3.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/package.json +1 -1
- package/src/request.js +7 -5
- package/src/response.js +11 -7
- package/src/router.js +2 -1
package/README.md
CHANGED
|
@@ -194,6 +194,7 @@ In general, basically all features and options are supported. Use [Express 4.x d
|
|
|
194
194
|
- ✅ req.cookies
|
|
195
195
|
- ✅ req.fresh
|
|
196
196
|
- ✅ req.hostname
|
|
197
|
+
- ✅ req.header
|
|
197
198
|
- ✅ req.headers
|
|
198
199
|
- ✅ req.headersDistinct
|
|
199
200
|
- ✅ req.rawHeaders
|
|
@@ -213,7 +214,7 @@ In general, basically all features and options are supported. Use [Express 4.x d
|
|
|
213
214
|
- ✅ req.subdomains
|
|
214
215
|
- ✅ req.xhr
|
|
215
216
|
- 🚧 req.route (route implementation is different from Express)
|
|
216
|
-
- 🚧 req.connection, req.socket (only `encrypted`, `remoteAddress`, `localPort` and `remotePort` are supported)
|
|
217
|
+
- 🚧 req.connection, req.socket (only `end()`, `encrypted`, `remoteAddress`, `localPort` and `remotePort` are supported)
|
|
217
218
|
- ✅ req.accepts()
|
|
218
219
|
- ✅ req.acceptsCharsets()
|
|
219
220
|
- ✅ req.acceptsEncodings()
|
package/package.json
CHANGED
package/src/request.js
CHANGED
|
@@ -271,6 +271,7 @@ module.exports = class Request extends Readable {
|
|
|
271
271
|
localPort: this.app.port,
|
|
272
272
|
remotePort: this.app.port,
|
|
273
273
|
encrypted: this.app.ssl,
|
|
274
|
+
end: (body) => this.res.end(body)
|
|
274
275
|
};
|
|
275
276
|
}
|
|
276
277
|
|
|
@@ -306,6 +307,7 @@ module.exports = class Request extends Readable {
|
|
|
306
307
|
}
|
|
307
308
|
return this.headers[field];
|
|
308
309
|
}
|
|
310
|
+
header = this.get
|
|
309
311
|
|
|
310
312
|
accepts(...types) {
|
|
311
313
|
return accepts(this).types(...types);
|
|
@@ -347,9 +349,9 @@ module.exports = class Request extends Readable {
|
|
|
347
349
|
get headers() {
|
|
348
350
|
// https://nodejs.org/api/http.html#messageheaders
|
|
349
351
|
if(this.#cachedHeaders) {
|
|
350
|
-
return
|
|
352
|
+
return this.#cachedHeaders;
|
|
351
353
|
}
|
|
352
|
-
this.#cachedHeaders = new NullObject();
|
|
354
|
+
this.#cachedHeaders = {...new NullObject()}; // seems to be faster
|
|
353
355
|
for (let index = 0, len = this.#rawHeadersEntries.length; index < len; index++) {
|
|
354
356
|
let [key, value] = this.#rawHeadersEntries[index];
|
|
355
357
|
key = key.toLowerCase();
|
|
@@ -372,14 +374,14 @@ module.exports = class Request extends Readable {
|
|
|
372
374
|
this.#cachedHeaders[key] = value;
|
|
373
375
|
}
|
|
374
376
|
}
|
|
375
|
-
return
|
|
377
|
+
return this.#cachedHeaders;
|
|
376
378
|
}
|
|
377
379
|
|
|
378
380
|
get headersDistinct() {
|
|
379
381
|
if(this.#cachedDistinctHeaders) {
|
|
380
382
|
return this.#cachedDistinctHeaders;
|
|
381
383
|
}
|
|
382
|
-
this.#cachedDistinctHeaders = new NullObject();
|
|
384
|
+
this.#cachedDistinctHeaders = {...new NullObject()};
|
|
383
385
|
this.#rawHeadersEntries.forEach((val) => {
|
|
384
386
|
const [key, value] = val;
|
|
385
387
|
if(!this.#cachedDistinctHeaders[key]) {
|
|
@@ -388,7 +390,7 @@ module.exports = class Request extends Readable {
|
|
|
388
390
|
}
|
|
389
391
|
this.#cachedDistinctHeaders[key].push(value);
|
|
390
392
|
});
|
|
391
|
-
return
|
|
393
|
+
return this.#cachedDistinctHeaders;
|
|
392
394
|
}
|
|
393
395
|
|
|
394
396
|
get rawHeaders() {
|
package/src/response.js
CHANGED
|
@@ -52,6 +52,10 @@ class Socket extends EventEmitter {
|
|
|
52
52
|
return !this.response.finished;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
end(body) {
|
|
56
|
+
this.response.end(body);
|
|
57
|
+
}
|
|
58
|
+
|
|
55
59
|
close() {
|
|
56
60
|
if(this.response.finished) {
|
|
57
61
|
return;
|
|
@@ -187,18 +191,19 @@ module.exports = class Response extends Writable {
|
|
|
187
191
|
}
|
|
188
192
|
writeHeaders(utf8) {
|
|
189
193
|
for(const header in this.headers) {
|
|
194
|
+
const value = this.headers[header];
|
|
190
195
|
if(header === 'content-length') {
|
|
191
196
|
// if content-length is set, disable chunked transfer encoding, since size is known
|
|
192
197
|
this.chunkedTransfer = false;
|
|
193
|
-
this.totalSize = parseInt(
|
|
198
|
+
this.totalSize = parseInt(value);
|
|
194
199
|
continue;
|
|
195
200
|
}
|
|
196
|
-
if(Array.isArray(
|
|
197
|
-
for(let
|
|
198
|
-
this._res.writeHeader(header,
|
|
201
|
+
if(Array.isArray(value)) {
|
|
202
|
+
for(let val of value) {
|
|
203
|
+
this._res.writeHeader(header, val);
|
|
199
204
|
}
|
|
200
205
|
} else {
|
|
201
|
-
this._res.writeHeader(header,
|
|
206
|
+
this._res.writeHeader(header, value);
|
|
202
207
|
}
|
|
203
208
|
}
|
|
204
209
|
if(!this.headers['content-type']) {
|
|
@@ -306,8 +311,7 @@ module.exports = class Response extends Writable {
|
|
|
306
311
|
// default options
|
|
307
312
|
if(typeof options.maxAge === 'string') {
|
|
308
313
|
options.maxAge = ms(options.maxAge);
|
|
309
|
-
}
|
|
310
|
-
if(typeof options.maxAge === 'undefined') {
|
|
314
|
+
} else if(typeof options.maxAge === 'undefined') {
|
|
311
315
|
options.maxAge = 0;
|
|
312
316
|
}
|
|
313
317
|
if(typeof options.lastModified === 'undefined') {
|
package/src/router.js
CHANGED
|
@@ -68,7 +68,7 @@ module.exports = class Router extends EventEmitter {
|
|
|
68
68
|
|
|
69
69
|
for(let method of methods) {
|
|
70
70
|
this[method] = (path, ...callbacks) => {
|
|
71
|
-
this.createRoute(method.toUpperCase(), path, this, ...callbacks);
|
|
71
|
+
return this.createRoute(method.toUpperCase(), path, this, ...callbacks);
|
|
72
72
|
};
|
|
73
73
|
};
|
|
74
74
|
}
|
|
@@ -580,6 +580,7 @@ module.exports = class Router extends EventEmitter {
|
|
|
580
580
|
}
|
|
581
581
|
}
|
|
582
582
|
this.createRoute('USE', path, this, ...callbacks);
|
|
583
|
+
return this;
|
|
583
584
|
}
|
|
584
585
|
|
|
585
586
|
route(path) {
|