ultimate-express 1.2.4 → 1.2.5
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/middlewares.js +33 -16
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ Tested using [bun-http-framework-benchmark](https://github.com/dimdenGD/bun-http
|
|
|
47
47
|
| elysia | bun | 72,112.447 | 82,589.71 | 69,356.08 | 64,391.55 |
|
|
48
48
|
| hyper-express | node | 66,356.707 | 80,002.53 | 69,953.76 | 49,113.83 |
|
|
49
49
|
| hono | bun | 63,944.627 | 74,550.47 | 62,810.28 | 54,473.13 |
|
|
50
|
-
| **ultimate-express** | **node** | **
|
|
50
|
+
| **ultimate-express** | **node** | **46,139.797** | **49,010.91** | **49,197.87** | **40,210.61** |
|
|
51
51
|
| oak | deno | 40,878.467 | 68,429.24 | 28,541.99 | 25,664.17 |
|
|
52
52
|
| express | bun | 35,937.977 | 41,329.97 | 34,339.79 | 32,144.17 |
|
|
53
53
|
| h3 | node | 35,423.263 | 41,243.68 | 34,429.26 | 30,596.85 |
|
package/package.json
CHANGED
package/src/middlewares.js
CHANGED
|
@@ -147,30 +147,47 @@ function json(options = {}) {
|
|
|
147
147
|
|
|
148
148
|
const abs = []
|
|
149
149
|
let totalSize = 0;
|
|
150
|
-
|
|
150
|
+
|
|
151
|
+
function onData(ab) {
|
|
151
152
|
abs.push(Buffer.from(ab));
|
|
152
153
|
totalSize += ab.length;
|
|
153
154
|
if(totalSize > options.limit) {
|
|
154
155
|
return next(new Error('Request entity too large'));
|
|
155
156
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function onEnd() {
|
|
160
|
+
const buf = Buffer.concat(abs);
|
|
161
|
+
if(options.verify) {
|
|
162
|
+
try {
|
|
163
|
+
options.verify(req, res, buf);
|
|
164
|
+
} catch(e) {
|
|
165
|
+
return next(e);
|
|
164
166
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
167
|
+
}
|
|
168
|
+
req.body = JSON.parse(buf, options.reviver);
|
|
169
|
+
if(options.strict) {
|
|
170
|
+
if(req.body && typeof req.body !== 'object') {
|
|
171
|
+
return next(new Error('Invalid body'));
|
|
170
172
|
}
|
|
171
|
-
next();
|
|
172
173
|
}
|
|
173
|
-
|
|
174
|
+
next();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if(!req.receivedData) {
|
|
178
|
+
// reading data directly from uWS is faster than from a stream
|
|
179
|
+
// if we are fast enough (not async), we can do it
|
|
180
|
+
// otherwise we need to use a stream since it already started streaming it
|
|
181
|
+
req._res.onData((ab, isLast) => {
|
|
182
|
+
onData(ab);
|
|
183
|
+
if(isLast) {
|
|
184
|
+
onEnd();
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
} else {
|
|
188
|
+
req.on('data', onData);
|
|
189
|
+
req.on('end', onEnd);
|
|
190
|
+
}
|
|
174
191
|
|
|
175
192
|
}
|
|
176
193
|
|