ultimate-express 1.1.8 → 1.2.0
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 +2 -1
- package/src/application.js +3 -4
- package/src/response.js +3 -2
- package/src/router.js +6 -2
- package/src/utils.js +14 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ultimate-express",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
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": {
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"cookie-signature": "^1.2.1",
|
|
45
45
|
"encodeurl": "^2.0.0",
|
|
46
46
|
"etag": "^1.8.1",
|
|
47
|
+
"fast-querystring": "^1.1.2",
|
|
47
48
|
"fresh": "^0.5.2",
|
|
48
49
|
"mime-types": "^2.1.35",
|
|
49
50
|
"ms": "^2.1.3",
|
package/src/application.js
CHANGED
|
@@ -16,9 +16,8 @@ limitations under the License.
|
|
|
16
16
|
|
|
17
17
|
const uWS = require("uWebSockets.js");
|
|
18
18
|
const Router = require("./router.js");
|
|
19
|
-
const { removeDuplicateSlashes, defaultSettings, compileTrust, createETagGenerator } = require("./utils.js");
|
|
20
|
-
const querystring = require("querystring");
|
|
21
|
-
const qs = require("qs");
|
|
19
|
+
const { removeDuplicateSlashes, defaultSettings, compileTrust, createETagGenerator, fastQueryParse } = require("./utils.js");
|
|
20
|
+
const querystring = require("fast-querystring");
|
|
22
21
|
const ViewClass = require("./view.js");
|
|
23
22
|
const path = require("path");
|
|
24
23
|
const os = require("os");
|
|
@@ -117,7 +116,7 @@ class Application extends Router {
|
|
|
117
116
|
}
|
|
118
117
|
} else if(key === 'query parser') {
|
|
119
118
|
if(value === 'extended') {
|
|
120
|
-
this.settings['query parser fn'] =
|
|
119
|
+
this.settings['query parser fn'] = fastQueryParse;
|
|
121
120
|
} else if(value === 'simple') {
|
|
122
121
|
this.settings['query parser fn'] = querystring.parse;
|
|
123
122
|
} else if(typeof value === 'function') {
|
package/src/response.js
CHANGED
|
@@ -238,9 +238,10 @@ module.exports = class Response extends Writable {
|
|
|
238
238
|
if(this.headersSent) {
|
|
239
239
|
throw new Error('Can\'t write body: Response was already sent');
|
|
240
240
|
}
|
|
241
|
+
const isBuffer = Buffer.isBuffer(body);
|
|
241
242
|
if(body === null || body === undefined) {
|
|
242
243
|
body = '';
|
|
243
|
-
} else if(typeof body === 'object' && !
|
|
244
|
+
} else if(typeof body === 'object' && !isBuffer) {
|
|
244
245
|
return this.json(body);
|
|
245
246
|
} else if(typeof body === 'number') {
|
|
246
247
|
if(arguments[1]) {
|
|
@@ -250,7 +251,7 @@ module.exports = class Response extends Writable {
|
|
|
250
251
|
deprecated('res.send(status)', 'res.sendStatus(status)');
|
|
251
252
|
return this.sendStatus(body);
|
|
252
253
|
}
|
|
253
|
-
} else {
|
|
254
|
+
} else if(!isBuffer) {
|
|
254
255
|
body = String(body);
|
|
255
256
|
}
|
|
256
257
|
if(typeof body === 'string') {
|
package/src/router.js
CHANGED
|
@@ -303,13 +303,17 @@ module.exports = class Router extends EventEmitter {
|
|
|
303
303
|
|
|
304
304
|
#extractParams(pattern, path) {
|
|
305
305
|
let match = pattern.exec(path);
|
|
306
|
-
|
|
306
|
+
const obj = match?.groups ?? {};
|
|
307
|
+
for(let i = 1; i < match.length; i++) {
|
|
308
|
+
obj[i - 1] = match[i];
|
|
309
|
+
}
|
|
310
|
+
return obj;
|
|
307
311
|
}
|
|
308
312
|
|
|
309
313
|
#preprocessRequest(req, res, route) {
|
|
310
314
|
return new Promise(async resolve => {
|
|
311
315
|
req.route = route;
|
|
312
|
-
if(typeof route.path === 'string' && route.path.includes(':') && route.pattern instanceof RegExp) {
|
|
316
|
+
if(typeof route.path === 'string' && (route.path.includes(':') || route.path.includes('*')) && route.pattern instanceof RegExp) {
|
|
313
317
|
let path = req.path;
|
|
314
318
|
if(req._stack.length > 0) {
|
|
315
319
|
path = path.replace(this.getFullMountpath(req), '');
|
package/src/utils.js
CHANGED
|
@@ -18,9 +18,19 @@ const mime = require("mime-types");
|
|
|
18
18
|
const path = require("path");
|
|
19
19
|
const proxyaddr = require("proxy-addr");
|
|
20
20
|
const qs = require("qs");
|
|
21
|
+
const querystring = require("fast-querystring");
|
|
21
22
|
const etag = require("etag");
|
|
22
23
|
const { Stats } = require("fs");
|
|
23
24
|
|
|
25
|
+
function fastQueryParse(query) {
|
|
26
|
+
if(query.length <= 128) {
|
|
27
|
+
if(!query.includes('[') && !query.includes('%5B') && !query.includes('.') && !query.includes('%2E')) {
|
|
28
|
+
return querystring.parse(query);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return qs.parse(query);
|
|
32
|
+
}
|
|
33
|
+
|
|
24
34
|
function removeDuplicateSlashes(path) {
|
|
25
35
|
return path.replace(/\/{2,}/g, '/');
|
|
26
36
|
}
|
|
@@ -36,7 +46,7 @@ function patternToRegex(pattern, isPrefix = false) {
|
|
|
36
46
|
let regexPattern = pattern
|
|
37
47
|
.replace(/\./g, '\\.')
|
|
38
48
|
.replace(/\-/g, '\\-')
|
|
39
|
-
.replace(/\*/g, '.*') // Convert * to .*
|
|
49
|
+
.replace(/\*/g, '(.*)') // Convert * to .*
|
|
40
50
|
.replace(/:(\w+)(\(.+?\))?/g, (match, param, regex) => {
|
|
41
51
|
return `(?<${param}>${regex ? regex + '($|\\/)' : '[^/]+'})`;
|
|
42
52
|
}); // Convert :param to capture group
|
|
@@ -115,7 +125,7 @@ const defaultSettings = {
|
|
|
115
125
|
'etag': 'weak',
|
|
116
126
|
'etag fn': () => createETagGenerator({ weak: true }),
|
|
117
127
|
'query parser': 'extended',
|
|
118
|
-
'query parser fn': () =>
|
|
128
|
+
'query parser fn': () => fastQueryParse,
|
|
119
129
|
'subdomain offset': 2,
|
|
120
130
|
'trust proxy': false,
|
|
121
131
|
'views': () => path.join(process.cwd(), 'views'),
|
|
@@ -300,5 +310,6 @@ module.exports = {
|
|
|
300
310
|
isPreconditionFailure,
|
|
301
311
|
createETagGenerator,
|
|
302
312
|
isRangeFresh,
|
|
303
|
-
findIndexStartingFrom
|
|
313
|
+
findIndexStartingFrom,
|
|
314
|
+
fastQueryParse
|
|
304
315
|
};
|