routup 1.0.0-alpha.6 → 1.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.
@@ -23,6 +23,7 @@ export declare enum HeaderName {
23
23
  COOKIE = "cookie",
24
24
  ETag = "etag",
25
25
  HOST = "host",
26
+ IF_MODIFIED_SINCE = "if-modified-since",
26
27
  IF_NONE_MATCH = "if-none-match",
27
28
  LAST_MODIFIED = "last-modified",
28
29
  LOCATION = "location",
package/dist/index.cjs CHANGED
@@ -55,12 +55,7 @@ var node_http = require('node:http');
55
55
  return weak ? `W/${tag}` : tag;
56
56
  }
57
57
 
58
- /*
59
- * Copyright (c) 2022-2023.
60
- * Author Peter Placzek (tada5hi)
61
- * For the full copyright and license information,
62
- * view the LICENSE file that was distributed with this source code.
63
- */ function isObject(item) {
58
+ function isObject(item) {
64
59
  return !!item && typeof item === 'object' && !Array.isArray(item);
65
60
  }
66
61
 
@@ -106,12 +101,7 @@ function buildTrustProxyFn(input) {
106
101
  return proxyAddr.compile(input || []);
107
102
  }
108
103
 
109
- /*
110
- * Copyright (c) 2022-2022.
111
- * Author Peter Placzek (tada5hi)
112
- * For the full copyright and license information,
113
- * view the LICENSE file that was distributed with this source code.
114
- */ function isInstance(input, name) {
104
+ function isInstance(input, name) {
115
105
  return typeof input === 'object' && input !== null && input['@instanceof'] === Symbol.for(name);
116
106
  }
117
107
 
@@ -132,12 +122,7 @@ function getCharsetForMimeType(type) {
132
122
  return undefined;
133
123
  }
134
124
 
135
- /*
136
- * Copyright (c) 2022.
137
- * Author Peter Placzek (tada5hi)
138
- * For the full copyright and license information,
139
- * view the LICENSE file that was distributed with this source code.
140
- */ function isPath(input) {
125
+ function isPath(input) {
141
126
  return typeof input === 'string' || input instanceof RegExp;
142
127
  }
143
128
 
@@ -167,12 +152,7 @@ function isPromise(p) {
167
152
  });
168
153
  }
169
154
 
170
- /*
171
- * Copyright (c) 2022-2023.
172
- * Author Peter Placzek (tada5hi)
173
- * For the full copyright and license information,
174
- * view the LICENSE file that was distributed with this source code.
175
- */ const TRAILING_SLASH_RE = /\/$|\/\?/;
155
+ const TRAILING_SLASH_RE = /\/$|\/\?/;
176
156
  function hasTrailingSlash(input = '', queryParams = false) {
177
157
  if (!queryParams) {
178
158
  return input.endsWith('/');
@@ -255,12 +235,7 @@ function getConfigOption(key) {
255
235
  return config.get(key);
256
236
  }
257
237
 
258
- /*
259
- * Copyright (c) 2022-2023.
260
- * Author Peter Placzek (tada5hi)
261
- * For the full copyright and license information,
262
- * view the LICENSE file that was distributed with this source code.
263
- */ exports.Method = void 0;
238
+ exports.Method = void 0;
264
239
  (function(Method) {
265
240
  Method["GET"] = 'get';
266
241
  Method["POST"] = 'post';
@@ -287,6 +262,7 @@ exports.HeaderName = void 0;
287
262
  HeaderName["COOKIE"] = 'cookie';
288
263
  HeaderName["ETag"] = 'etag';
289
264
  HeaderName["HOST"] = 'host';
265
+ HeaderName["IF_MODIFIED_SINCE"] = 'if-modified-since';
290
266
  HeaderName["IF_NONE_MATCH"] = 'if-none-match';
291
267
  HeaderName["LAST_MODIFIED"] = 'last-modified';
292
268
  HeaderName["LOCATION"] = 'location';
@@ -357,13 +333,8 @@ function extendRequestBody(req, key, value) {
357
333
  setRequestBody(req, key, value);
358
334
  }
359
335
 
360
- /*
361
- * Copyright (c) 2022.
362
- * Author Peter Placzek (tada5hi)
363
- * For the full copyright and license information,
364
- * view the LICENSE file that was distributed with this source code.
365
- */ function isRequestCacheable(req, modifiedTime) {
366
- const modifiedSince = req.headers['if-modified-since'];
336
+ function isRequestCacheable(req, modifiedTime) {
337
+ const modifiedSince = req.headers[exports.HeaderName.IF_MODIFIED_SINCE];
367
338
  if (!modifiedSince) {
368
339
  return false;
369
340
  }
@@ -454,12 +425,7 @@ function unsetRequestEnv(req, key) {
454
425
  }
455
426
  }
456
427
 
457
- /*
458
- * Copyright (c) 2022.
459
- * Author Peter Placzek (tada5hi)
460
- * For the full copyright and license information,
461
- * view the LICENSE file that was distributed with this source code.
462
- */ function getRequestHeader(req, name) {
428
+ function getRequestHeader(req, name) {
463
429
  return req.headers[name];
464
430
  }
465
431
  function setRequestHeader(req, name, value) {
@@ -612,12 +578,7 @@ function getRequestIP(req, options) {
612
578
  return proxyAddr(req, trustProxy);
613
579
  }
614
580
 
615
- /*
616
- * Copyright (c) 2022.
617
- * Author Peter Placzek (tada5hi)
618
- * For the full copyright and license information,
619
- * view the LICENSE file that was distributed with this source code.
620
- */ const ReqMountPathSymbol = Symbol.for('ReqMountPath');
581
+ const ReqMountPathSymbol = Symbol.for('ReqMountPath');
621
582
  function useRequestMountPath(req) {
622
583
  if (ReqMountPathSymbol in req) {
623
584
  return req[ReqMountPathSymbol];
@@ -628,12 +589,7 @@ function setRequestMountPath(req, basePath) {
628
589
  req[ReqMountPathSymbol] = basePath;
629
590
  }
630
591
 
631
- /*
632
- * Copyright (c) 2022.
633
- * Author Peter Placzek (tada5hi)
634
- * For the full copyright and license information,
635
- * view the LICENSE file that was distributed with this source code.
636
- */ const ParamsSymbol = Symbol.for('ReqParams');
592
+ const ParamsSymbol = Symbol.for('ReqParams');
637
593
  function useRequestParams(req) {
638
594
  /* istanbul ignore next */ if ('params' in req) {
639
595
  return req.params;
@@ -655,15 +611,20 @@ function setRequestParam(req, key, value) {
655
611
  setRequestParams(req, params);
656
612
  }
657
613
 
614
+ const PathSymbol = Symbol.for('ReqPath');
658
615
  function useRequestPath(req) {
659
616
  if ('path' in req) {
660
617
  return req.path;
661
618
  }
619
+ if (PathSymbol in req) {
620
+ return req[PathSymbol];
621
+ }
662
622
  if (typeof req.url === 'undefined') {
663
623
  return '/';
664
624
  }
665
625
  const parsed = new node_url.URL(req.url, 'http://localhost/');
666
- return parsed.pathname;
626
+ req[PathSymbol] = parsed.pathname;
627
+ return req[PathSymbol];
667
628
  }
668
629
 
669
630
  function getRequestProtocol(req, options) {
@@ -741,12 +702,7 @@ function extendRequestQuery(req, key, value) {
741
702
  setRequestQuery(req, key, value);
742
703
  }
743
704
 
744
- /*
745
- * Copyright (c) 2022.
746
- * Author Peter Placzek (tada5hi)
747
- * For the full copyright and license information,
748
- * view the LICENSE file that was distributed with this source code.
749
- */ function setResponseCacheHeaders(res, options) {
705
+ function setResponseCacheHeaders(res, options) {
750
706
  options = options || {};
751
707
  const cacheControls = [
752
708
  'public'
@@ -761,12 +717,7 @@ function extendRequestQuery(req, key, value) {
761
717
  res.setHeader('cache-control', cacheControls.join(', '));
762
718
  }
763
719
 
764
- /*
765
- * Copyright (c) 2022.
766
- * Author Peter Placzek (tada5hi)
767
- * For the full copyright and license information,
768
- * view the LICENSE file that was distributed with this source code.
769
- */ function appendResponseHeader(res, name, value) {
720
+ function appendResponseHeader(res, name, value) {
770
721
  let header = res.getHeader(name);
771
722
  if (!header) {
772
723
  res.setHeader(name, value);
@@ -958,12 +909,7 @@ function sendCreated(res, chunk) {
958
909
  return send(res, chunk);
959
910
  }
960
911
 
961
- /*
962
- * Copyright (c) 2022.
963
- * Author Peter Placzek (tada5hi)
964
- * For the full copyright and license information,
965
- * view the LICENSE file that was distributed with this source code.
966
- */ function sendStream(res, stream, fn) {
912
+ function sendStream(res, stream, fn) {
967
913
  stream.on('open', ()=>{
968
914
  stream.pipe(res);
969
915
  });