routup 3.3.0 → 4.0.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/dist/adapters/node/module.d.ts +0 -1
- package/dist/handler/module.d.ts +1 -1
- package/dist/index.cjs +89 -103
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +89 -103
- package/dist/index.mjs.map +1 -1
- package/dist/path/type.d.ts +3 -3
- package/dist/request/helpers/env.d.ts +4 -4
- package/dist/request/helpers/header-accept-encoding.d.ts +0 -1
- package/dist/request/helpers/header.d.ts +0 -1
- package/dist/request/module.d.ts +0 -1
- package/dist/request/types.d.ts +0 -1
- package/dist/response/helpers/header.d.ts +0 -1
- package/dist/response/types.d.ts +0 -1
- package/dist/types.d.ts +0 -2
- package/dist/utils/etag/module.d.ts +0 -2
- package/dist/utils/etag/type.d.ts +0 -1
- package/dist/utils/object.d.ts +2 -0
- package/dist/utils/stream.d.ts +0 -2
- package/package.json +11 -11
package/dist/index.mjs
CHANGED
|
@@ -62,55 +62,6 @@ function isRequestCacheable(req, modifiedTime) {
|
|
|
62
62
|
return new Date(modifiedSince) >= modifiedTime;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
const envSymbol = Symbol.for('ReqEnv');
|
|
66
|
-
function setRequestEnv(req, key, value) {
|
|
67
|
-
if (envSymbol in req) {
|
|
68
|
-
if (typeof key === 'object') {
|
|
69
|
-
if (value) {
|
|
70
|
-
req[envSymbol] = merge(req[envSymbol], key);
|
|
71
|
-
} else {
|
|
72
|
-
req[envSymbol] = key;
|
|
73
|
-
}
|
|
74
|
-
} else {
|
|
75
|
-
req[envSymbol][key] = value;
|
|
76
|
-
}
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
if (typeof key === 'object') {
|
|
80
|
-
req[envSymbol] = key;
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
req[envSymbol] = {
|
|
84
|
-
[key]: value
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
function useRequestEnv(req, key) {
|
|
88
|
-
if (envSymbol in req) {
|
|
89
|
-
if (typeof key === 'string') {
|
|
90
|
-
return req[envSymbol][key];
|
|
91
|
-
}
|
|
92
|
-
return req[envSymbol];
|
|
93
|
-
}
|
|
94
|
-
if (typeof key === 'string') {
|
|
95
|
-
return undefined;
|
|
96
|
-
}
|
|
97
|
-
return {};
|
|
98
|
-
}
|
|
99
|
-
function unsetRequestEnv(req, key) {
|
|
100
|
-
if (envSymbol in req) {
|
|
101
|
-
if (hasOwnProperty(req[envSymbol], key)) {
|
|
102
|
-
delete req[envSymbol][key];
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function getRequestHeader(req, name) {
|
|
108
|
-
return req.headers[name];
|
|
109
|
-
}
|
|
110
|
-
function setRequestHeader(req, name, value) {
|
|
111
|
-
req.headers[name] = value;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
65
|
/*
|
|
115
66
|
Set-Cookie header field-values are sometimes comma joined in one string. This splits them without choking on commas
|
|
116
67
|
that are within a single set-cookie field-value, such as in the Expires portion.
|
|
@@ -186,6 +137,12 @@ function setRequestHeader(req, name, value) {
|
|
|
186
137
|
function isObject(item) {
|
|
187
138
|
return !!item && typeof item === 'object' && !Array.isArray(item);
|
|
188
139
|
}
|
|
140
|
+
function setProperty(record, property, value) {
|
|
141
|
+
record[property] = value;
|
|
142
|
+
}
|
|
143
|
+
function getProperty(req, property) {
|
|
144
|
+
return req[property];
|
|
145
|
+
}
|
|
189
146
|
|
|
190
147
|
/**
|
|
191
148
|
* Determine if object is a Stats object.
|
|
@@ -322,7 +279,7 @@ function basename(input, extension) {
|
|
|
322
279
|
if (!lastSegment) {
|
|
323
280
|
return input;
|
|
324
281
|
}
|
|
325
|
-
return
|
|
282
|
+
return lastSegment;
|
|
326
283
|
}
|
|
327
284
|
|
|
328
285
|
function isPromise(p) {
|
|
@@ -378,12 +335,66 @@ function isWebResponse(input) {
|
|
|
378
335
|
return typeof Response !== 'undefined' && input instanceof Response;
|
|
379
336
|
}
|
|
380
337
|
|
|
381
|
-
const
|
|
338
|
+
const symbol$4 = Symbol.for('ReqEnv');
|
|
339
|
+
function setRequestEnv(req, key, value) {
|
|
340
|
+
const propertyValue = getProperty(req, symbol$4);
|
|
341
|
+
if (propertyValue) {
|
|
342
|
+
if (typeof key === 'object') {
|
|
343
|
+
if (value) {
|
|
344
|
+
setProperty(req, symbol$4, merge(propertyValue, key));
|
|
345
|
+
} else {
|
|
346
|
+
setProperty(req, symbol$4, key);
|
|
347
|
+
}
|
|
348
|
+
} else {
|
|
349
|
+
propertyValue[key] = value;
|
|
350
|
+
setProperty(req, symbol$4, propertyValue);
|
|
351
|
+
}
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
if (typeof key === 'object') {
|
|
355
|
+
setProperty(req, symbol$4, key);
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
setProperty(req, symbol$4, {
|
|
359
|
+
[key]: value
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
function useRequestEnv(req, key) {
|
|
363
|
+
const propertyValue = getProperty(req, symbol$4);
|
|
364
|
+
if (propertyValue) {
|
|
365
|
+
if (typeof key !== 'undefined') {
|
|
366
|
+
return propertyValue[key];
|
|
367
|
+
}
|
|
368
|
+
return propertyValue;
|
|
369
|
+
}
|
|
370
|
+
if (typeof key !== 'undefined') {
|
|
371
|
+
return undefined;
|
|
372
|
+
}
|
|
373
|
+
return {};
|
|
374
|
+
}
|
|
375
|
+
function unsetRequestEnv(req, key) {
|
|
376
|
+
const propertyValue = getProperty(req, symbol$4);
|
|
377
|
+
if (hasOwnProperty(propertyValue, key)) {
|
|
378
|
+
delete propertyValue[key];
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function getRequestHeader(req, name) {
|
|
383
|
+
return req.headers[name];
|
|
384
|
+
}
|
|
385
|
+
function setRequestHeader(req, name, value) {
|
|
386
|
+
req.headers[name] = value;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
const symbol$3 = Symbol.for('ReqNegotiator');
|
|
382
390
|
function useRequestNegotiator(req) {
|
|
383
|
-
|
|
384
|
-
|
|
391
|
+
let value = getProperty(req, symbol$3);
|
|
392
|
+
if (value) {
|
|
393
|
+
return value;
|
|
385
394
|
}
|
|
386
|
-
|
|
395
|
+
value = new Negotiator(req);
|
|
396
|
+
setProperty(req, symbol$3, value);
|
|
397
|
+
return value;
|
|
387
398
|
}
|
|
388
399
|
|
|
389
400
|
function getRequestAcceptableContentTypes(req) {
|
|
@@ -511,13 +522,10 @@ function findRouterOption(key, path) {
|
|
|
511
522
|
|
|
512
523
|
const routerSymbol = Symbol.for('ReqRouterID');
|
|
513
524
|
function setRequestRouterPath(req, path) {
|
|
514
|
-
req
|
|
525
|
+
setProperty(req, routerSymbol, path);
|
|
515
526
|
}
|
|
516
527
|
function useRequestRouterPath(req) {
|
|
517
|
-
|
|
518
|
-
return req[routerSymbol];
|
|
519
|
-
}
|
|
520
|
-
return undefined;
|
|
528
|
+
return getProperty(req, routerSymbol);
|
|
521
529
|
}
|
|
522
530
|
|
|
523
531
|
function getRequestHostName(req, options) {
|
|
@@ -562,32 +570,23 @@ function getRequestIP(req, options) {
|
|
|
562
570
|
return addrs[addrs.length - 1];
|
|
563
571
|
}
|
|
564
572
|
|
|
565
|
-
const
|
|
573
|
+
const symbol$2 = Symbol.for('ReqMountPath');
|
|
566
574
|
function useRequestMountPath(req) {
|
|
567
|
-
|
|
568
|
-
return req[ReqMountPathSymbol];
|
|
569
|
-
}
|
|
570
|
-
return '/';
|
|
575
|
+
return getProperty(req, symbol$2) || '/';
|
|
571
576
|
}
|
|
572
577
|
function setRequestMountPath(req, basePath) {
|
|
573
|
-
req
|
|
578
|
+
setProperty(req, symbol$2, basePath);
|
|
574
579
|
}
|
|
575
580
|
|
|
576
|
-
const
|
|
581
|
+
const symbol$1 = Symbol.for('ReqParams');
|
|
577
582
|
function useRequestParams(req) {
|
|
578
|
-
|
|
579
|
-
return req.params;
|
|
580
|
-
}
|
|
581
|
-
if (ParamsSymbol in req) {
|
|
582
|
-
return req[ParamsSymbol];
|
|
583
|
-
}
|
|
584
|
-
return {};
|
|
583
|
+
return getProperty(req, symbol$1) || getProperty(req, 'params') || {};
|
|
585
584
|
}
|
|
586
585
|
function useRequestParam(req, key) {
|
|
587
586
|
return useRequestParams(req)[key];
|
|
588
587
|
}
|
|
589
588
|
function setRequestParams(req, data) {
|
|
590
|
-
req
|
|
589
|
+
setProperty(req, symbol$1, data);
|
|
591
590
|
}
|
|
592
591
|
function setRequestParam(req, key, value) {
|
|
593
592
|
const params = useRequestParams(req);
|
|
@@ -597,18 +596,16 @@ function setRequestParam(req, key, value) {
|
|
|
597
596
|
|
|
598
597
|
const PathSymbol = Symbol.for('ReqPath');
|
|
599
598
|
function useRequestPath(req) {
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
if (PathSymbol in req) {
|
|
604
|
-
return req[PathSymbol];
|
|
599
|
+
const path = getProperty(req, 'path') || getProperty(req, PathSymbol);
|
|
600
|
+
if (path) {
|
|
601
|
+
return path;
|
|
605
602
|
}
|
|
606
603
|
if (typeof req.url === 'undefined') {
|
|
607
604
|
return '/';
|
|
608
605
|
}
|
|
609
606
|
const parsed = new URL(req.url, 'http://localhost/');
|
|
610
|
-
req
|
|
611
|
-
return
|
|
607
|
+
setProperty(req, PathSymbol, parsed.pathname);
|
|
608
|
+
return parsed.pathname;
|
|
612
609
|
}
|
|
613
610
|
|
|
614
611
|
function getRequestProtocol(req, options) {
|
|
@@ -755,18 +752,15 @@ function setResponseCacheHeaders(res, options) {
|
|
|
755
752
|
res.setHeader('cache-control', cacheControls.join(', '));
|
|
756
753
|
}
|
|
757
754
|
|
|
758
|
-
const
|
|
755
|
+
const symbol = Symbol.for('ResGone');
|
|
759
756
|
function isResponseGone(res) {
|
|
760
757
|
if (res.headersSent || res.writableEnded) {
|
|
761
758
|
return true;
|
|
762
759
|
}
|
|
763
|
-
|
|
764
|
-
return res[GoneSymbol];
|
|
765
|
-
}
|
|
766
|
-
return false;
|
|
760
|
+
return getProperty(res, symbol) ?? false;
|
|
767
761
|
}
|
|
768
762
|
function setResponseGone(res, value) {
|
|
769
|
-
res
|
|
763
|
+
setProperty(res, symbol, value);
|
|
770
764
|
}
|
|
771
765
|
|
|
772
766
|
function serializeEventStreamMessage(message) {
|
|
@@ -1728,12 +1722,14 @@ class PathMatcher {
|
|
|
1728
1722
|
this.regexpKeys = [];
|
|
1729
1723
|
this.path = path;
|
|
1730
1724
|
this.regexpOptions = options || {};
|
|
1731
|
-
|
|
1725
|
+
const regexp = pathToRegexp(path, options);
|
|
1726
|
+
this.regexp = regexp;
|
|
1727
|
+
this.regexpKeys = regexp.keys;
|
|
1732
1728
|
}
|
|
1733
1729
|
}
|
|
1734
1730
|
|
|
1735
1731
|
function isPath(input) {
|
|
1736
|
-
return typeof input === 'string'
|
|
1732
|
+
return typeof input === 'string';
|
|
1737
1733
|
}
|
|
1738
1734
|
|
|
1739
1735
|
class Handler {
|
|
@@ -1926,15 +1922,9 @@ class Router {
|
|
|
1926
1922
|
this.pathMatcher = undefined;
|
|
1927
1923
|
return;
|
|
1928
1924
|
}
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
});
|
|
1933
|
-
} else {
|
|
1934
|
-
this.pathMatcher = new PathMatcher(value, {
|
|
1935
|
-
end: false
|
|
1936
|
-
});
|
|
1937
|
-
}
|
|
1925
|
+
this.pathMatcher = new PathMatcher(withLeadingSlash(withoutTrailingSlash(`${value}`)), {
|
|
1926
|
+
end: false
|
|
1927
|
+
});
|
|
1938
1928
|
}
|
|
1939
1929
|
// --------------------------------------------------
|
|
1940
1930
|
async executePipelineStep(context) {
|
|
@@ -2156,11 +2146,7 @@ class Router {
|
|
|
2156
2146
|
for(let i = 0; i < input.length; i++){
|
|
2157
2147
|
const item = input[i];
|
|
2158
2148
|
if (isPath(item)) {
|
|
2159
|
-
|
|
2160
|
-
path = withLeadingSlash(item);
|
|
2161
|
-
} else {
|
|
2162
|
-
path = item;
|
|
2163
|
-
}
|
|
2149
|
+
path = withLeadingSlash(item);
|
|
2164
2150
|
continue;
|
|
2165
2151
|
}
|
|
2166
2152
|
if (isRouterInstance(item)) {
|