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 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** | **44,081.737** | **51,753.24** | **48,389.84** | **32,102.13** |
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ultimate-express",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
4
4
  "description": "The Ultimate Express. Fastest http server with full Express compatibility, based on uWebSockets.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -147,30 +147,47 @@ function json(options = {}) {
147
147
 
148
148
  const abs = []
149
149
  let totalSize = 0;
150
- req._res.onData((ab, isLast) => {
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
- if(isLast) {
157
- const buf = Buffer.concat(abs);
158
- if(options.verify) {
159
- try {
160
- options.verify(req, res, buf);
161
- } catch(e) {
162
- return next(e);
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
- req.body = JSON.parse(buf, options.reviver);
166
- if(options.strict) {
167
- if(req.body && typeof req.body !== 'object') {
168
- return next(new Error('Invalid body'));
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