ultimate-express 1.2.12 → 1.2.14
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 +1 -1
- package/package.json +1 -1
- package/src/request.js +24 -1
- package/src/router.js +2 -0
package/README.md
CHANGED
|
@@ -45,7 +45,7 @@ For full table with other runtimes, check [here](https://github.com/dimdenGD/bun
|
|
|
45
45
|
| -------------------- | ------------- | ------------- | ------------- | ------------- |
|
|
46
46
|
| uws | 94,296.49 | 108,551.92 | 104,756.22 | 69,581.33 |
|
|
47
47
|
| hyper-express | 66,356.707 | 80,002.53 | 69,953.76 | 49,113.83 |
|
|
48
|
-
| **ultimate-express** | **
|
|
48
|
+
| **ultimate-express** | **52,275.677** | **58,756.34** | **55,038.4** | **43,032.29** |
|
|
49
49
|
| h3 | 35,423.263 | 41,243.68 | 34,429.26 | 30,596.85 |
|
|
50
50
|
| fastify | 33,094.62 | 40,147.67 | 40,076.35 | 19,059.84 |
|
|
51
51
|
| hono | 26,576.02 | 36,215.35 | 34,656.12 | 8,856.59 |
|
package/package.json
CHANGED
package/src/request.js
CHANGED
|
@@ -29,6 +29,8 @@ const discardedDuplicates = [
|
|
|
29
29
|
"server", "user-agent"
|
|
30
30
|
];
|
|
31
31
|
|
|
32
|
+
let key = 0;
|
|
33
|
+
|
|
32
34
|
module.exports = class Request extends Readable {
|
|
33
35
|
#cachedQuery = null;
|
|
34
36
|
#cachedHeaders = null;
|
|
@@ -43,6 +45,10 @@ module.exports = class Request extends Readable {
|
|
|
43
45
|
this._req.forEach((key, value) => {
|
|
44
46
|
this.#rawHeadersEntries.push([key, value]);
|
|
45
47
|
});
|
|
48
|
+
this.key = key++;
|
|
49
|
+
if(key > 100000) {
|
|
50
|
+
key = 0;
|
|
51
|
+
}
|
|
46
52
|
this.app = app;
|
|
47
53
|
this.urlQuery = req.getQuery() ?? '';
|
|
48
54
|
if(this.urlQuery) {
|
|
@@ -65,7 +71,12 @@ module.exports = class Request extends Readable {
|
|
|
65
71
|
this._paramStack = [];
|
|
66
72
|
this.bufferedData = Buffer.allocUnsafe(0);
|
|
67
73
|
this.receivedData = false;
|
|
68
|
-
|
|
74
|
+
// reading ip is very slow in UWS, so its better to not do it unless truly needed
|
|
75
|
+
if(this.app.needsIpAfterResponse || this.key < 100) {
|
|
76
|
+
// if app needs ip after response, read it now because after response its not accessible
|
|
77
|
+
// also read it for first 100 requests to not error
|
|
78
|
+
this.rawIp = this._res.getRemoteAddress();
|
|
79
|
+
}
|
|
69
80
|
|
|
70
81
|
const additionalMethods = this.app.get('body methods');
|
|
71
82
|
// skip reading body for non-POST requests
|
|
@@ -222,6 +233,18 @@ module.exports = class Request extends Readable {
|
|
|
222
233
|
if(this.#cachedParsedIp) {
|
|
223
234
|
return this.#cachedParsedIp;
|
|
224
235
|
}
|
|
236
|
+
const finished = !this.res.socket.writable;
|
|
237
|
+
if(finished) {
|
|
238
|
+
// mark app as one that needs ip after response
|
|
239
|
+
this.app.needsIpAfterResponse = true;
|
|
240
|
+
}
|
|
241
|
+
if(!this.rawIp) {
|
|
242
|
+
if(finished) {
|
|
243
|
+
// fallback once
|
|
244
|
+
return '127.0.0.1';
|
|
245
|
+
}
|
|
246
|
+
this.rawIp = this._res.getRemoteAddress();
|
|
247
|
+
}
|
|
225
248
|
let ip = '';
|
|
226
249
|
if(this.rawIp.byteLength === 4) {
|
|
227
250
|
// ipv4
|