dx-server 0.13.0 → 0.14.0-alpha.2
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 +397 -265
- package/lib/body.js +1 -1
- package/lib/body.js.map +1 -0
- package/lib/bodyHelpers.js +22 -9
- package/lib/bodyHelpers.js.map +1 -0
- package/lib/dx.d.ts +1 -1
- package/lib/dx.js +12 -6
- package/lib/dx.js.map +1 -0
- package/lib/dxHelpers.d.ts +2 -1
- package/lib/dxHelpers.js +105 -87
- package/lib/dxHelpers.js.map +1 -0
- package/lib/helpers.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -0
- package/lib/logger.d.ts +3 -2
- package/lib/logger.js +54 -46
- package/lib/logger.js.map +1 -0
- package/lib/router.js +5 -5
- package/lib/router.js.map +1 -0
- package/lib/static.js +4 -3
- package/lib/static.js.map +1 -0
- package/lib/staticHelpers.d.ts +5 -1
- package/lib/staticHelpers.js +150 -134
- package/lib/staticHelpers.js.map +1 -0
- package/lib/stream.d.ts +1 -1
- package/lib/stream.js +11 -5
- package/lib/stream.js.map +1 -0
- package/lib/vendors/contentType.js +7 -30
- package/lib/vendors/contentType.js.map +1 -0
- package/lib/vendors/etag.d.ts +2 -2
- package/lib/vendors/etag.js +15 -25
- package/lib/vendors/etag.js.map +1 -0
- package/lib/vendors/fresh.js +10 -17
- package/lib/vendors/fresh.js.map +1 -0
- package/lib/vendors/mime.js +4 -4
- package/lib/vendors/mime.js.map +1 -0
- package/lib/vendors/mimeDb.d.ts +2544 -2544
- package/lib/vendors/mimeDb.js +7100 -7079
- package/lib/vendors/mimeDb.js.map +1 -0
- package/lib/vendors/mimeScore.js +10 -11
- package/lib/vendors/mimeScore.js.map +1 -0
- package/lib/vendors/rangeParser.d.ts +2 -10
- package/lib/vendors/rangeParser.js +16 -29
- package/lib/vendors/rangeParser.js.map +1 -0
- package/package.json +32 -27
package/lib/vendors/mimeScore.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
// 'mime-score' back-ported to CommonJS
|
|
2
2
|
// Score RFC facets (see https://tools.ietf.org/html/rfc6838#section-3)
|
|
3
|
-
const
|
|
3
|
+
const facetScores = {
|
|
4
4
|
'prs.': 100,
|
|
5
5
|
'x-': 200,
|
|
6
6
|
'x.': 300,
|
|
7
7
|
'vnd.': 400,
|
|
8
|
-
default: 900
|
|
8
|
+
default: 900,
|
|
9
9
|
};
|
|
10
10
|
// Score mime source (Logic originally from `jshttp/mime-types` module)
|
|
11
|
-
const
|
|
11
|
+
const sourceScores = {
|
|
12
12
|
nginx: 10,
|
|
13
13
|
apache: 20,
|
|
14
14
|
iana: 40,
|
|
15
|
-
default: 30 // definitions added by `jshttp/mime-db` project?
|
|
15
|
+
default: 30, // definitions added by `jshttp/mime-db` project?
|
|
16
16
|
};
|
|
17
|
-
const
|
|
17
|
+
const typeScores = {
|
|
18
18
|
// prefer application/xml over text/xml
|
|
19
19
|
// prefer application/rtf over text/rtf
|
|
20
20
|
application: 1,
|
|
@@ -24,21 +24,20 @@ const TYPE_SCORES = {
|
|
|
24
24
|
// See https://www.rfc-editor.org/rfc/rfc4337.html#section-2
|
|
25
25
|
audio: 2,
|
|
26
26
|
video: 3,
|
|
27
|
-
default: 0
|
|
27
|
+
default: 0,
|
|
28
28
|
};
|
|
29
29
|
/**
|
|
30
30
|
* Get each component of the score for a mime type. The sum of these is the
|
|
31
31
|
* total score. The higher the score, the more "official" the type.
|
|
32
32
|
*/
|
|
33
33
|
export function mimeScore(mimeType, source = 'default') {
|
|
34
|
-
if (mimeType === 'application/octet-stream')
|
|
34
|
+
if (mimeType === 'application/octet-stream')
|
|
35
35
|
return 0;
|
|
36
|
-
}
|
|
37
36
|
const [type, subtype] = mimeType.split('/');
|
|
38
37
|
const facet = subtype.replace(/(\.|x-).*/, '$1');
|
|
39
|
-
const facetScore =
|
|
40
|
-
const sourceScore =
|
|
41
|
-
const typeScore =
|
|
38
|
+
const facetScore = facetScores[facet] || facetScores.default;
|
|
39
|
+
const sourceScore = sourceScores[source] || sourceScores.default;
|
|
40
|
+
const typeScore = typeScores[type] || typeScores.default;
|
|
42
41
|
// All else being equal prefer shorter types
|
|
43
42
|
const lengthScore = 1 - mimeType.length / 100;
|
|
44
43
|
return facetScore + sourceScore + typeScore + lengthScore;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mimeScore.js","sourceRoot":"","sources":["../../src/vendors/mimeScore.ts"],"names":[],"mappings":"AAAA,uCAAuC;AAEvC,uEAAuE;AACvE,MAAM,WAAW,GAAG;IACnB,MAAM,EAAE,GAAG;IACX,IAAI,EAAE,GAAG;IACT,IAAI,EAAE,GAAG;IACT,MAAM,EAAE,GAAG;IACX,OAAO,EAAE,GAAG;CACZ,CAAA;AAED,uEAAuE;AACvE,MAAM,YAAY,GAAG;IACpB,KAAK,EAAE,EAAE;IACT,MAAM,EAAE,EAAE;IACV,IAAI,EAAE,EAAE;IACR,OAAO,EAAE,EAAE,EAAE,iDAAiD;CAC9D,CAAA;AAED,MAAM,UAAU,GAAG;IAClB,uCAAuC;IACvC,uCAAuC;IACvC,WAAW,EAAE,CAAC;IAEd,8CAA8C;IAC9C,IAAI,EAAE,CAAC;IAEP,uDAAuD;IACvD,4DAA4D;IAC5D,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;IAER,OAAO,EAAE,CAAC;CACV,CAAA;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,QAAgB,EAAE,MAAM,GAAG,SAAS;IAC7D,IAAI,QAAQ,KAAK,0BAA0B;QAAE,OAAO,CAAC,CAAA;IAErD,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAE3C,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA;IAEhD,MAAM,UAAU,GAAG,WAAW,CAAC,KAAiC,CAAC,IAAI,WAAW,CAAC,OAAO,CAAA;IACxF,MAAM,WAAW,GAAG,YAAY,CAAC,MAAmC,CAAC,IAAI,YAAY,CAAC,OAAO,CAAA;IAC7F,MAAM,SAAS,GAAG,UAAU,CAAC,IAA+B,CAAC,IAAI,UAAU,CAAC,OAAO,CAAA;IAEnF,4CAA4C;IAC5C,MAAM,WAAW,GAAG,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,GAAG,CAAA;IAE7C,OAAO,UAAU,GAAG,WAAW,GAAG,SAAS,GAAG,WAAW,CAAA;AAC1D,CAAC","sourcesContent":["// 'mime-score' back-ported to CommonJS\n\n// Score RFC facets (see https://tools.ietf.org/html/rfc6838#section-3)\nconst facetScores = {\n\t'prs.': 100,\n\t'x-': 200,\n\t'x.': 300,\n\t'vnd.': 400,\n\tdefault: 900,\n}\n\n// Score mime source (Logic originally from `jshttp/mime-types` module)\nconst sourceScores = {\n\tnginx: 10,\n\tapache: 20,\n\tiana: 40,\n\tdefault: 30, // definitions added by `jshttp/mime-db` project?\n}\n\nconst typeScores = {\n\t// prefer application/xml over text/xml\n\t// prefer application/rtf over text/rtf\n\tapplication: 1,\n\n\t// prefer font/woff over application/font-woff\n\tfont: 2,\n\n\t// prefer video/mp4 over audio/mp4 over application/mp4\n\t// See https://www.rfc-editor.org/rfc/rfc4337.html#section-2\n\taudio: 2,\n\tvideo: 3,\n\n\tdefault: 0,\n}\n\n/**\n * Get each component of the score for a mime type. The sum of these is the\n * total score. The higher the score, the more \"official\" the type.\n */\nexport function mimeScore(mimeType: string, source = 'default') {\n\tif (mimeType === 'application/octet-stream') return 0\n\n\tconst [type, subtype] = mimeType.split('/')\n\n\tconst facet = subtype.replace(/(\\.|x-).*/, '$1')\n\n\tconst facetScore = facetScores[facet as keyof typeof facetScores] || facetScores.default\n\tconst sourceScore = sourceScores[source as keyof typeof sourceScores] || sourceScores.default\n\tconst typeScore = typeScores[type as keyof typeof typeScores] || typeScores.default\n\n\t// All else being equal prefer shorter types\n\tconst lengthScore = 1 - mimeType.length / 100\n\n\treturn facetScore + sourceScore + typeScore + lengthScore\n}\n"]}
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parse "Range" header `str` relative to the given file `size`.
|
|
3
|
-
*
|
|
4
|
-
* @param {Number} size
|
|
5
|
-
* @param {String} str
|
|
6
|
-
* @param {Object} [options]
|
|
7
|
-
* @return {Array}
|
|
8
|
-
* @public
|
|
9
|
-
*/
|
|
10
1
|
interface Range {
|
|
11
2
|
start: number;
|
|
12
3
|
end: number;
|
|
@@ -14,7 +5,8 @@ interface Range {
|
|
|
14
5
|
export type Ranges = Range[] & {
|
|
15
6
|
type: string;
|
|
16
7
|
};
|
|
17
|
-
export declare function parseRange(size: number, str: string | undefined,
|
|
8
|
+
export declare function parseRange(size: number, str: string | undefined, { combine, maxRanges }?: {
|
|
18
9
|
combine?: boolean;
|
|
10
|
+
maxRanges?: number;
|
|
19
11
|
}): Ranges | -1 | -2;
|
|
20
12
|
export {};
|
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
* @param {Number} size
|
|
5
|
-
* @param {String} str
|
|
6
|
-
* @param {Object} [options]
|
|
7
|
-
* @return {Array}
|
|
8
|
-
* @public
|
|
9
|
-
*/
|
|
10
|
-
export function parseRange(size, str, options) {
|
|
11
|
-
if (typeof str !== 'string') {
|
|
1
|
+
export function parseRange(size, str, { combine, maxRanges = 100 } = {}) {
|
|
2
|
+
if (typeof str !== 'string')
|
|
12
3
|
throw new TypeError('argument str must be a string');
|
|
13
|
-
}
|
|
14
4
|
const index = str.indexOf('=');
|
|
15
|
-
if (index === -1)
|
|
5
|
+
if (index === -1)
|
|
16
6
|
return -2;
|
|
17
|
-
}
|
|
18
7
|
// split the range string
|
|
19
8
|
const arr = str.slice(index + 1).split(',');
|
|
9
|
+
// bound the number of ranges: each costs a parseInt and combineRanges sorts O(n log n),
|
|
10
|
+
// so an attacker could amplify CPU with a header full of tiny ranges
|
|
11
|
+
if (arr.length > maxRanges)
|
|
12
|
+
return -1;
|
|
20
13
|
const ranges = [];
|
|
21
14
|
// add ranges type
|
|
22
15
|
ranges.type = str.slice(0, index);
|
|
@@ -31,30 +24,24 @@ export function parseRange(size, str, options) {
|
|
|
31
24
|
end = size - 1;
|
|
32
25
|
// nnn-
|
|
33
26
|
}
|
|
34
|
-
else if (isNaN(end))
|
|
27
|
+
else if (isNaN(end))
|
|
35
28
|
end = size - 1;
|
|
36
|
-
}
|
|
37
29
|
// limit last-byte-pos to current length
|
|
38
|
-
if (end > size - 1)
|
|
30
|
+
if (end > size - 1)
|
|
39
31
|
end = size - 1;
|
|
40
|
-
}
|
|
41
32
|
// invalid or unsatisifiable
|
|
42
|
-
if (isNaN(start) || isNaN(end) || start > end || start < 0)
|
|
33
|
+
if (isNaN(start) || isNaN(end) || start > end || start < 0)
|
|
43
34
|
continue;
|
|
44
|
-
}
|
|
45
35
|
// add range
|
|
46
36
|
ranges.push({
|
|
47
37
|
start: start,
|
|
48
|
-
end: end
|
|
38
|
+
end: end,
|
|
49
39
|
});
|
|
50
40
|
}
|
|
51
|
-
|
|
52
|
-
|
|
41
|
+
// unsatisifiable
|
|
42
|
+
if (ranges.length < 1)
|
|
53
43
|
return -1;
|
|
54
|
-
|
|
55
|
-
return options && options.combine
|
|
56
|
-
? combineRanges(ranges)
|
|
57
|
-
: ranges;
|
|
44
|
+
return combine ? combineRanges(ranges) : ranges;
|
|
58
45
|
}
|
|
59
46
|
/**
|
|
60
47
|
* Combine overlapping & adjacent ranges.
|
|
@@ -92,7 +79,7 @@ function mapWithIndex(range, index) {
|
|
|
92
79
|
return {
|
|
93
80
|
start: range.start,
|
|
94
81
|
end: range.end,
|
|
95
|
-
index: index
|
|
82
|
+
index: index,
|
|
96
83
|
};
|
|
97
84
|
}
|
|
98
85
|
/**
|
|
@@ -102,7 +89,7 @@ function mapWithIndex(range, index) {
|
|
|
102
89
|
function mapWithoutIndex(range) {
|
|
103
90
|
return {
|
|
104
91
|
start: range.start,
|
|
105
|
-
end: range.end
|
|
92
|
+
end: range.end,
|
|
106
93
|
};
|
|
107
94
|
}
|
|
108
95
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rangeParser.js","sourceRoot":"","sources":["../../src/vendors/rangeParser.ts"],"names":[],"mappings":"AASA,MAAM,UAAU,UAAU,CACzB,IAAY,EACZ,GAAuB,EACvB,EAAC,OAAO,EAAE,SAAS,GAAG,GAAG,KAA6C,EAAE;IAExE,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,MAAM,IAAI,SAAS,CAAC,+BAA+B,CAAC,CAAA;IAEjF,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAE9B,IAAI,KAAK,KAAK,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC,CAAA;IAE3B,yBAAyB;IACzB,MAAM,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAE3C,wFAAwF;IACxF,qEAAqE;IACrE,IAAI,GAAG,CAAC,MAAM,GAAG,SAAS;QAAE,OAAO,CAAC,CAAC,CAAA;IAErC,MAAM,MAAM,GAAG,EAAuB,CAAA;IAEtC,kBAAkB;IAClB,MAAM,CAAC,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;IAEjC,mBAAmB;IACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAC/B,IAAI,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;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SAAS,gBAAgB,CAAC,CAAe,EAAE,CAAe;IACzD,OAAO,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAA;AACzB,CAAC","sourcesContent":["interface Range {\n\tstart: number\n\tend: number\n}\ninterface IndexedRange extends Range {\n\tindex: number\n}\nexport type Ranges = Range[] & {type: string}\n\nexport function parseRange(\n\tsize: number,\n\tstr: string | undefined,\n\t{combine, maxRanges = 100}: {combine?: boolean; maxRanges?: number} = {},\n): Ranges | -1 | -2 {\n\tif (typeof str !== 'string') throw new TypeError('argument str must be a string')\n\n\tconst index = str.indexOf('=')\n\n\tif (index === -1) return -2\n\n\t// split the range string\n\tconst arr = str.slice(index + 1).split(',')\n\n\t// bound the number of ranges: each costs a parseInt and combineRanges sorts O(n log n),\n\t// so an attacker could amplify CPU with a header full of tiny ranges\n\tif (arr.length > maxRanges) return -1\n\n\tconst ranges = [] as unknown as Ranges\n\n\t// add ranges type\n\tranges.type = str.slice(0, index)\n\n\t// parse all ranges\n\tfor (let i = 0; i < arr.length; i++) {\n\t\tconst range = arr[i].split('-')\n\t\tlet start = parseInt(range[0], 10)\n\t\tlet end = parseInt(range[1], 10)\n\n\t\t// -nnn\n\t\tif (isNaN(start)) {\n\t\t\tstart = size - end\n\t\t\tend = size - 1\n\t\t\t// nnn-\n\t\t} else if (isNaN(end)) end = size - 1\n\n\t\t// limit last-byte-pos to current length\n\t\tif (end > size - 1) end = size - 1\n\n\t\t// invalid or unsatisifiable\n\t\tif (isNaN(start) || isNaN(end) || start > end || start < 0) continue\n\n\t\t// add range\n\t\tranges.push({\n\t\t\tstart: start,\n\t\t\tend: end,\n\t\t})\n\t}\n\n\t// unsatisifiable\n\tif (ranges.length < 1) return -1\n\n\treturn combine ? combineRanges(ranges) : ranges\n}\n\n/**\n * Combine overlapping & adjacent ranges.\n * @private\n */\n\nfunction combineRanges(ranges: Ranges) {\n\tconst ordered = ranges.map(mapWithIndex).sort(sortByRangeStart)\n\n\tlet j = 0\n\tfor (let i = 1; i < ordered.length; i++) {\n\t\tconst range = ordered[i]\n\t\tconst current = ordered[j]\n\n\t\tif (range.start > current.end + 1) {\n\t\t\t// next range\n\t\t\tordered[++j] = range\n\t\t} else if (range.end > current.end) {\n\t\t\t// extend range\n\t\t\tcurrent.end = range.end\n\t\t\tcurrent.index = Math.min(current.index, range.index)\n\t\t}\n\t}\n\n\t// trim ordered array\n\tordered.length = j + 1\n\n\t// generate combined range\n\tconst combined = ordered.sort(sortByRangeIndex).map(mapWithoutIndex) as unknown as Ranges\n\n\t// copy ranges type\n\tcombined.type = ranges.type\n\n\treturn combined\n}\n\n/**\n * Map function to add index value to ranges.\n * @private\n */\n\nfunction mapWithIndex(range: Range, index: number) {\n\treturn {\n\t\tstart: range.start,\n\t\tend: range.end,\n\t\tindex: index,\n\t}\n}\n\n/**\n * Map function to remove index value from ranges.\n * @private\n */\n\nfunction mapWithoutIndex(range: IndexedRange) {\n\treturn {\n\t\tstart: range.start,\n\t\tend: range.end,\n\t}\n}\n\n/**\n * Sort function to sort ranges by index.\n * @private\n */\n\nfunction sortByRangeIndex(a: IndexedRange, b: IndexedRange) {\n\treturn a.index - b.index\n}\n\n/**\n * Sort function to sort ranges by start position.\n * @private\n */\n\nfunction sortByRangeStart(a: IndexedRange, b: IndexedRange) {\n\treturn a.start - b.start\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,29 +1,34 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
2
|
+
"name": "dx-server",
|
|
3
|
+
"version": "0.14.0-alpha.2",
|
|
4
|
+
"main": "./lib/index.js",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/tranvansang/dx-server.git"
|
|
8
|
+
},
|
|
9
|
+
"author": "Sang Tran <t@sang.jp>",
|
|
10
|
+
"files": [
|
|
11
|
+
"lib"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"default": "./lib/index.js",
|
|
16
|
+
"types": "./lib/index.d.ts"
|
|
17
|
+
},
|
|
18
|
+
"./helpers": {
|
|
19
|
+
"default": "./lib/helpers.js",
|
|
20
|
+
"types": "./lib/helpers.d.ts"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"scripts": {
|
|
25
|
+
"prepublishOnly": "tsc",
|
|
26
|
+
"test": "tsc && node --test test/*.test.ts",
|
|
27
|
+
"coverage": "tsc && node --test --experimental-test-coverage --test-coverage-include='lib/**' --test-coverage-exclude='lib/vendors/mimeDb.js' --test-coverage-exclude='test/**' test/*.test.ts"
|
|
28
|
+
},
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^25.6.0",
|
|
32
|
+
"typescript": "^6.0.2"
|
|
33
|
+
}
|
|
29
34
|
}
|