ultimate-express 1.2.3 → 1.2.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ultimate-express",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
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": {
package/src/index.js CHANGED
@@ -17,7 +17,7 @@ limitations under the License.
17
17
  const Application = require("./application.js");
18
18
  const Router = require("./router.js");
19
19
  const bodyParser = require("body-parser");
20
- const { static } = require("./middlewares.js");
20
+ const { static, json } = require("./middlewares.js");
21
21
  const Request = require("./request.js");
22
22
  const Response = require("./response.js");
23
23
 
@@ -30,7 +30,7 @@ Application.response = Response.prototype;
30
30
 
31
31
  Application.static = static;
32
32
 
33
- Application.json = bodyParser.json;
33
+ Application.json = json;
34
34
  Application.urlencoded = bodyParser.urlencoded;
35
35
  Application.text = bodyParser.text;
36
36
  Application.raw = bodyParser.raw;
@@ -128,6 +128,10 @@ function json(options = {}) {
128
128
  if(!type || contentType !== options.type) {
129
129
  return next();
130
130
  }
131
+ // skip reading body twice
132
+ if(req.body) {
133
+ return next();
134
+ }
131
135
 
132
136
  // skip reading body for non-POST requests
133
137
  // this makes it +10k req/sec faster
@@ -141,9 +145,10 @@ function json(options = {}) {
141
145
  return next();
142
146
  }
143
147
 
144
- const abs = [], totalSize = 0;
148
+ const abs = []
149
+ let totalSize = 0;
145
150
  req._res.onData((ab, isLast) => {
146
- abs.push(ab);
151
+ abs.push(Buffer.from(ab));
147
152
  totalSize += ab.length;
148
153
  if(totalSize > options.limit) {
149
154
  return next(new Error('Request entity too large'));
@@ -172,5 +177,6 @@ function json(options = {}) {
172
177
  }
173
178
 
174
179
  module.exports = {
175
- static
180
+ static,
181
+ json
176
182
  };