@zuplo/cli 6.71.0 → 6.71.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/node_modules/@fastify/reply-from/node_modules/undici/docs/docs/api/Client.md +3 -0
- package/node_modules/@fastify/reply-from/node_modules/undici/docs/docs/api/Cookies.md +27 -0
- package/node_modules/@fastify/reply-from/node_modules/undici/docs/docs/api/Socks5ProxyAgent.md +1 -0
- package/node_modules/@fastify/reply-from/node_modules/undici/lib/core/socks5-client.js +14 -4
- package/node_modules/@fastify/reply-from/node_modules/undici/lib/core/socks5-utils.js +18 -4
- package/node_modules/@fastify/reply-from/node_modules/undici/lib/dispatcher/agent.js +1 -1
- package/node_modules/@fastify/reply-from/node_modules/undici/lib/dispatcher/balanced-pool.js +1 -1
- package/node_modules/@fastify/reply-from/node_modules/undici/lib/dispatcher/client-h1.js +69 -1
- package/node_modules/@fastify/reply-from/node_modules/undici/lib/dispatcher/client.js +3 -2
- package/node_modules/@fastify/reply-from/node_modules/undici/lib/dispatcher/dispatcher-base.js +19 -0
- package/node_modules/@fastify/reply-from/node_modules/undici/lib/dispatcher/pool.js +1 -1
- package/node_modules/@fastify/reply-from/node_modules/undici/lib/dispatcher/proxy-agent.js +2 -1
- package/node_modules/@fastify/reply-from/node_modules/undici/lib/dispatcher/socks5-proxy-agent.js +45 -34
- package/node_modules/@fastify/reply-from/node_modules/undici/lib/util/cache.js +8 -2
- package/node_modules/@fastify/reply-from/node_modules/undici/lib/web/cookies/parse.js +17 -25
- package/node_modules/@fastify/reply-from/node_modules/undici/lib/web/websocket/permessage-deflate.js +13 -31
- package/node_modules/@fastify/reply-from/node_modules/undici/lib/web/websocket/receiver.js +80 -23
- package/node_modules/@fastify/reply-from/node_modules/undici/lib/web/websocket/stream/websocketstream.js +8 -1
- package/node_modules/@fastify/reply-from/node_modules/undici/lib/web/websocket/websocket.js +8 -1
- package/node_modules/@fastify/reply-from/node_modules/undici/package.json +1 -1
- package/node_modules/@fastify/reply-from/node_modules/undici/types/client.d.ts +16 -0
- package/node_modules/@zuplo/core/package.json +1 -1
- package/node_modules/@zuplo/graphql/package.json +1 -1
- package/node_modules/@zuplo/openapi-tools/package.json +1 -1
- package/node_modules/@zuplo/otel/package.json +1 -1
- package/node_modules/@zuplo/runtime/package.json +1 -1
- package/node_modules/body-parser/README.md +16 -1
- package/node_modules/body-parser/index.js +4 -20
- package/node_modules/body-parser/lib/read.js +17 -17
- package/node_modules/body-parser/lib/types/json.js +60 -32
- package/node_modules/body-parser/lib/types/raw.js +3 -3
- package/node_modules/body-parser/lib/types/text.js +3 -3
- package/node_modules/body-parser/lib/types/urlencoded.js +16 -20
- package/node_modules/body-parser/lib/utils.js +18 -16
- package/node_modules/body-parser/node_modules/content-type/LICENSE +22 -0
- package/node_modules/body-parser/node_modules/content-type/README.md +69 -0
- package/node_modules/body-parser/node_modules/content-type/dist/index.d.ts +26 -0
- package/node_modules/body-parser/node_modules/content-type/dist/index.js +170 -0
- package/node_modules/body-parser/node_modules/content-type/dist/index.js.map +1 -0
- package/node_modules/body-parser/node_modules/content-type/package.json +52 -0
- package/node_modules/body-parser/node_modules/http-errors/HISTORY.md +186 -0
- package/node_modules/body-parser/node_modules/http-errors/LICENSE +23 -0
- package/node_modules/body-parser/node_modules/http-errors/README.md +169 -0
- package/node_modules/body-parser/node_modules/http-errors/index.js +290 -0
- package/node_modules/body-parser/node_modules/http-errors/package.json +54 -0
- package/node_modules/body-parser/package.json +23 -10
- package/package.json +6 -6
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
* @private
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const debug = require('debug')('body-parser:json')
|
|
16
|
+
const read = require('../read')
|
|
17
|
+
const { normalizeOptions } = require('../utils')
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Module exports.
|
|
@@ -33,10 +33,10 @@ module.exports = json
|
|
|
33
33
|
* %x0A / ; Line feed or New line
|
|
34
34
|
* %x0D ) ; Carriage return
|
|
35
35
|
*/
|
|
36
|
-
|
|
36
|
+
const FIRST_CHAR_REGEXP = /^[\x20\x09\x0a\x0d]*([^\x20\x09\x0a\x0d])/ // eslint-disable-line no-control-regex
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
const JSON_SYNTAX_CHAR = '#'
|
|
39
|
+
const JSON_SYNTAX_REGEXP = /#+/g
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* Create a middleware to parse JSON bodies.
|
|
@@ -48,23 +48,61 @@ var JSON_SYNTAX_REGEXP = /#+/g
|
|
|
48
48
|
function json (options) {
|
|
49
49
|
const normalizedOptions = normalizeOptions(options, 'application/json')
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
var strict = options?.strict !== false
|
|
51
|
+
const parse = createJsonParser(options)
|
|
53
52
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
53
|
+
const readOptions = {
|
|
54
|
+
...normalizedOptions,
|
|
55
|
+
// assert charset per RFC 7159 sec 8.1
|
|
56
|
+
isValidCharset: (charset) => charset.slice(0, 4) === 'utf-'
|
|
57
|
+
}
|
|
60
58
|
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
return function jsonParser (req, res, next) {
|
|
60
|
+
read(req, res, next, parse, debug, readOptions)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Create a JSON parse function
|
|
66
|
+
*
|
|
67
|
+
* @param {object} [options]
|
|
68
|
+
* @return {function}
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
function createJsonParser (options) {
|
|
72
|
+
const reviver = options?.reviver
|
|
73
|
+
const strict = options?.strict !== false
|
|
74
|
+
|
|
75
|
+
if (strict) {
|
|
76
|
+
return function parse (body) {
|
|
77
|
+
if (body.length === 0) {
|
|
78
|
+
// special-case empty json body, as it's a common client-side mistake
|
|
79
|
+
// TODO: maybe make this configurable or part of "strict" option
|
|
80
|
+
return {}
|
|
81
|
+
}
|
|
63
82
|
|
|
83
|
+
const first = firstchar(body)
|
|
64
84
|
if (first !== '{' && first !== '[') {
|
|
65
85
|
debug('strict violation')
|
|
66
86
|
throw createStrictSyntaxError(body, first)
|
|
67
87
|
}
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
debug('parse json')
|
|
91
|
+
return JSON.parse(body, reviver)
|
|
92
|
+
} catch (e) {
|
|
93
|
+
throw normalizeJsonSyntaxError(e, {
|
|
94
|
+
message: e.message,
|
|
95
|
+
stack: e.stack
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return function parse (body) {
|
|
102
|
+
if (body.length === 0) {
|
|
103
|
+
// special-case empty json body, as it's a common client-side mistake
|
|
104
|
+
// TODO: maybe make this configurable or part of "strict" option
|
|
105
|
+
return {}
|
|
68
106
|
}
|
|
69
107
|
|
|
70
108
|
try {
|
|
@@ -77,16 +115,6 @@ function json (options) {
|
|
|
77
115
|
})
|
|
78
116
|
}
|
|
79
117
|
}
|
|
80
|
-
|
|
81
|
-
const readOptions = {
|
|
82
|
-
...normalizedOptions,
|
|
83
|
-
// assert charset per RFC 7159 sec 8.1
|
|
84
|
-
isValidCharset: (charset) => charset.slice(0, 4) === 'utf-'
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return function jsonParser (req, res, next) {
|
|
88
|
-
read(req, res, next, parse, debug, readOptions)
|
|
89
|
-
}
|
|
90
118
|
}
|
|
91
119
|
|
|
92
120
|
/**
|
|
@@ -98,8 +126,8 @@ function json (options) {
|
|
|
98
126
|
* @private
|
|
99
127
|
*/
|
|
100
128
|
function createStrictSyntaxError (str, char) {
|
|
101
|
-
|
|
102
|
-
|
|
129
|
+
const index = str.indexOf(char)
|
|
130
|
+
let partial = ''
|
|
103
131
|
|
|
104
132
|
if (index !== -1) {
|
|
105
133
|
partial = str.substring(0, index) + JSON_SYNTAX_CHAR.repeat(str.length - index)
|
|
@@ -125,7 +153,7 @@ function createStrictSyntaxError (str, char) {
|
|
|
125
153
|
* @private
|
|
126
154
|
*/
|
|
127
155
|
function firstchar (str) {
|
|
128
|
-
|
|
156
|
+
const match = FIRST_CHAR_REGEXP.exec(str)
|
|
129
157
|
|
|
130
158
|
return match
|
|
131
159
|
? match[1]
|
|
@@ -141,10 +169,10 @@ function firstchar (str) {
|
|
|
141
169
|
* @private
|
|
142
170
|
*/
|
|
143
171
|
function normalizeJsonSyntaxError (error, obj) {
|
|
144
|
-
|
|
172
|
+
const keys = Object.getOwnPropertyNames(error)
|
|
145
173
|
|
|
146
|
-
for (
|
|
147
|
-
|
|
174
|
+
for (let i = 0; i < keys.length; i++) {
|
|
175
|
+
const key = keys[i]
|
|
148
176
|
if (key !== 'stack' && key !== 'message') {
|
|
149
177
|
delete error[key]
|
|
150
178
|
}
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
* Module dependencies.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const debug = require('debug')('body-parser:raw')
|
|
14
|
+
const read = require('../read')
|
|
15
|
+
const { normalizeOptions, passthrough } = require('../utils')
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Module exports.
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
* Module dependencies.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const debug = require('debug')('body-parser:text')
|
|
14
|
+
const read = require('../read')
|
|
15
|
+
const { normalizeOptions, passthrough } = require('../utils')
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Module exports.
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
* @private
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
const createError = require('http-errors')
|
|
16
|
+
const debug = require('debug')('body-parser:urlencoded')
|
|
17
|
+
const read = require('../read')
|
|
18
|
+
const qs = require('qs')
|
|
19
|
+
const { normalizeOptions } = require('../utils')
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Module exports.
|
|
@@ -39,13 +39,7 @@ function urlencoded (options) {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
// create the appropriate query parser
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
function parse (body, encoding) {
|
|
45
|
-
return body.length
|
|
46
|
-
? queryparse(body, encoding)
|
|
47
|
-
: {}
|
|
48
|
-
}
|
|
42
|
+
const parse = createQueryParser(options)
|
|
49
43
|
|
|
50
44
|
const readOptions = {
|
|
51
45
|
...normalizedOptions,
|
|
@@ -66,13 +60,13 @@ function urlencoded (options) {
|
|
|
66
60
|
* @private
|
|
67
61
|
*/
|
|
68
62
|
function createQueryParser (options) {
|
|
69
|
-
|
|
70
|
-
|
|
63
|
+
const extended = Boolean(options?.extended)
|
|
64
|
+
let parameterLimit = options?.parameterLimit !== undefined
|
|
71
65
|
? options?.parameterLimit
|
|
72
66
|
: 1000
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
67
|
+
const charsetSentinel = options?.charsetSentinel
|
|
68
|
+
const interpretNumericEntities = options?.interpretNumericEntities
|
|
69
|
+
const depth = extended ? (options?.depth !== undefined ? options?.depth : 32) : 0
|
|
76
70
|
|
|
77
71
|
if (isNaN(parameterLimit) || parameterLimit < 1) {
|
|
78
72
|
throw new TypeError('option parameterLimit must be a positive number')
|
|
@@ -86,8 +80,10 @@ function createQueryParser (options) {
|
|
|
86
80
|
parameterLimit = parameterLimit | 0
|
|
87
81
|
}
|
|
88
82
|
|
|
89
|
-
return function
|
|
90
|
-
|
|
83
|
+
return function parse (body, encoding) {
|
|
84
|
+
if (!body.length) return {}
|
|
85
|
+
|
|
86
|
+
const paramCount = parameterCount(body, parameterLimit)
|
|
91
87
|
|
|
92
88
|
if (paramCount === undefined) {
|
|
93
89
|
debug('too many parameters')
|
|
@@ -96,7 +92,7 @@ function createQueryParser (options) {
|
|
|
96
92
|
})
|
|
97
93
|
}
|
|
98
94
|
|
|
99
|
-
|
|
95
|
+
const arrayLimit = extended ? Math.max(100, paramCount) : paramCount
|
|
100
96
|
|
|
101
97
|
debug('parse ' + (extended ? 'extended ' : '') + 'urlencoding')
|
|
102
98
|
try {
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* Module dependencies.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const bytes = require('bytes')
|
|
8
|
+
const contentType = require('content-type')
|
|
9
|
+
const typeis = require('type-is')
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Module exports.
|
|
@@ -25,11 +25,9 @@ module.exports = {
|
|
|
25
25
|
* @private
|
|
26
26
|
*/
|
|
27
27
|
function getCharset (req) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return undefined
|
|
32
|
-
}
|
|
28
|
+
const header = req.headers['content-type']
|
|
29
|
+
if (!header) return undefined
|
|
30
|
+
return contentType.parse(header).parameters.charset?.toLowerCase()
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
/**
|
|
@@ -59,20 +57,24 @@ function normalizeOptions (options, defaultType) {
|
|
|
59
57
|
throw new TypeError('defaultType must be provided')
|
|
60
58
|
}
|
|
61
59
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
?
|
|
65
|
-
: options
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
60
|
+
const inflate = options?.inflate !== false
|
|
61
|
+
const limit = typeof options?.limit === 'undefined' || options?.limit === null
|
|
62
|
+
? 102400 // 100kb default
|
|
63
|
+
: bytes.parse(options.limit)
|
|
64
|
+
const type = options?.type || defaultType
|
|
65
|
+
const verify = options?.verify || false
|
|
66
|
+
const defaultCharset = options?.defaultCharset || 'utf-8'
|
|
67
|
+
|
|
68
|
+
if (limit === null) {
|
|
69
|
+
throw new TypeError(`option limit "${String(options.limit)}" is invalid`)
|
|
70
|
+
}
|
|
69
71
|
|
|
70
72
|
if (verify !== false && typeof verify !== 'function') {
|
|
71
73
|
throw new TypeError('option verify must be function')
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
// create the appropriate type checking function
|
|
75
|
-
|
|
77
|
+
const shouldParse = typeof type !== 'function'
|
|
76
78
|
? typeChecker(type)
|
|
77
79
|
: type
|
|
78
80
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
(The MIT License)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 Douglas Christopher Wilson
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# content-type
|
|
2
|
+
|
|
3
|
+
[![NPM version][npm-image]][npm-url]
|
|
4
|
+
[![NPM downloads][downloads-image]][downloads-url]
|
|
5
|
+
[![Build status][build-image]][build-url]
|
|
6
|
+
[![Build coverage][coverage-image]][coverage-url]
|
|
7
|
+
[![License][license-image]][license-url]
|
|
8
|
+
|
|
9
|
+
Create and parse HTTP `Content-Type` header.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install content-type
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## API
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
const contentType = require("content-type");
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### contentType.parse(string, options?)
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
const obj = contentType.parse("image/svg+xml; charset=utf-8");
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Parse a `Content-Type` header. This will return an object with the following properties (examples are shown for the string `'image/svg+xml; charset=utf-8'`):
|
|
30
|
+
|
|
31
|
+
- `type`: The media type. Example: `'image/svg+xml'`.
|
|
32
|
+
- `parameters`: An object of the parameters in the media type (parameter name is always lower case). Example: `{charset: 'utf-8'}`.
|
|
33
|
+
|
|
34
|
+
The parser is lenient and does not error. You should validate `type` and `parameters` before trusting them.
|
|
35
|
+
|
|
36
|
+
#### Options
|
|
37
|
+
|
|
38
|
+
- `parameters` (default: `true`): Set to `false` to skip parameters.
|
|
39
|
+
|
|
40
|
+
### contentType.format(obj)
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
const str = contentType.format({
|
|
44
|
+
type: "image/svg+xml",
|
|
45
|
+
parameters: { charset: "utf-8" },
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Format an object into a `Content-Type` header. This will return a string of the content type for the given object with the following properties (examples are shown that produce the string `'image/svg+xml; charset=utf-8'`):
|
|
50
|
+
|
|
51
|
+
- `type`: The media type. Example: `'image/svg+xml'`.
|
|
52
|
+
- `parameters`: An optional object of the parameters in the media type. Example: `{charset: 'utf-8'}`.
|
|
53
|
+
|
|
54
|
+
Throws a `TypeError` if the object contains an invalid type or parameter names.
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
|
|
58
|
+
[MIT](LICENSE)
|
|
59
|
+
|
|
60
|
+
[npm-image]: https://img.shields.io/npm/v/content-type
|
|
61
|
+
[npm-url]: https://npmjs.org/package/content-type
|
|
62
|
+
[downloads-image]: https://img.shields.io/npm/dm/content-type
|
|
63
|
+
[downloads-url]: https://npmjs.org/package/content-type
|
|
64
|
+
[build-image]: https://img.shields.io/github/actions/workflow/status/jshttp/content-type/ci.yml?branch=master
|
|
65
|
+
[build-url]: https://github.com/jshttp/content-type/actions/workflows/ci.yml?query=branch%3Amaster
|
|
66
|
+
[coverage-image]: https://img.shields.io/codecov/c/gh/jshttp/content-type
|
|
67
|
+
[coverage-url]: https://codecov.io/gh/jshttp/content-type
|
|
68
|
+
[license-image]: http://img.shields.io/npm/l/content-type.svg?style=flat
|
|
69
|
+
[license-url]: LICENSE
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* content-type
|
|
3
|
+
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
4
|
+
* MIT Licensed
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* The content type object contains a type string and optional parameters.
|
|
8
|
+
*/
|
|
9
|
+
export interface ContentType {
|
|
10
|
+
type: string;
|
|
11
|
+
parameters: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Format an object into a `Content-Type` header.
|
|
15
|
+
*/
|
|
16
|
+
export declare function format(obj: Partial<ContentType>): string;
|
|
17
|
+
/**
|
|
18
|
+
* Options for parsing a `Content-Type` header.
|
|
19
|
+
*/
|
|
20
|
+
export interface ParseOptions {
|
|
21
|
+
parameters?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Parse a `Content-Type` header.
|
|
25
|
+
*/
|
|
26
|
+
export declare function parse(header: string, options?: ParseOptions): ContentType;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* content-type
|
|
4
|
+
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
5
|
+
* MIT Licensed
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.format = format;
|
|
9
|
+
exports.parse = parse;
|
|
10
|
+
const TEXT_REGEXP = /^[\u0009\u0020-\u007e\u0080-\u00ff]*$/;
|
|
11
|
+
const TOKEN_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
12
|
+
/**
|
|
13
|
+
* RegExp to match chars that must be quoted-pair in RFC 9110 sec 5.6.4
|
|
14
|
+
*/
|
|
15
|
+
const QUOTE_REGEXP = /[\\"]/g;
|
|
16
|
+
/**
|
|
17
|
+
* RegExp to match type in RFC 9110 sec 8.3.1
|
|
18
|
+
*
|
|
19
|
+
* media-type = type "/" subtype
|
|
20
|
+
* type = token
|
|
21
|
+
* subtype = token
|
|
22
|
+
*/
|
|
23
|
+
const TYPE_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
24
|
+
/**
|
|
25
|
+
* Null object perf optimization. Faster than `Object.create(null)` and `{ __proto__: null }`.
|
|
26
|
+
*/
|
|
27
|
+
const NullObject = /* @__PURE__ */ (() => {
|
|
28
|
+
const C = function () { };
|
|
29
|
+
C.prototype = Object.create(null);
|
|
30
|
+
return C;
|
|
31
|
+
})();
|
|
32
|
+
/**
|
|
33
|
+
* Format an object into a `Content-Type` header.
|
|
34
|
+
*/
|
|
35
|
+
function format(obj) {
|
|
36
|
+
const { type, parameters } = obj;
|
|
37
|
+
if (!type || !TYPE_REGEXP.test(type)) {
|
|
38
|
+
throw new TypeError(`Invalid type: ${type}`);
|
|
39
|
+
}
|
|
40
|
+
let result = type;
|
|
41
|
+
if (parameters) {
|
|
42
|
+
for (const param of Object.keys(parameters)) {
|
|
43
|
+
if (!TOKEN_REGEXP.test(param)) {
|
|
44
|
+
throw new TypeError(`Invalid parameter name: ${param}`);
|
|
45
|
+
}
|
|
46
|
+
result += `; ${param}=${qstring(parameters[param])}`;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Parse a `Content-Type` header.
|
|
53
|
+
*/
|
|
54
|
+
function parse(header, options) {
|
|
55
|
+
const len = header.length;
|
|
56
|
+
let index = skipOWS(header, 0, len);
|
|
57
|
+
const valueStart = index;
|
|
58
|
+
index = skipValue(header, index, len);
|
|
59
|
+
const valueEnd = trailingOWS(header, valueStart, index);
|
|
60
|
+
const type = header.slice(valueStart, valueEnd).toLowerCase();
|
|
61
|
+
const parameters = options?.parameters === false
|
|
62
|
+
? new NullObject()
|
|
63
|
+
: parseParameters(header, index, len);
|
|
64
|
+
return { type, parameters };
|
|
65
|
+
}
|
|
66
|
+
const SP = 32; // " "
|
|
67
|
+
const HTAB = 9; // "\t"
|
|
68
|
+
const SEMI = 59; // ";"
|
|
69
|
+
const EQ = 61; // "="
|
|
70
|
+
const DQUOTE = 34; // '"'
|
|
71
|
+
const BSLASH = 92; // "\\"
|
|
72
|
+
/**
|
|
73
|
+
* Parses the parameters of a `Content-Type` header starting at the given index.
|
|
74
|
+
*/
|
|
75
|
+
function parseParameters(header, index, len) {
|
|
76
|
+
const parameters = new NullObject();
|
|
77
|
+
parameter: while (index < len) {
|
|
78
|
+
index = skipOWS(header, index + 1 /* Skip over ; */, len);
|
|
79
|
+
const keyStart = index;
|
|
80
|
+
while (index < len) {
|
|
81
|
+
const code = header.charCodeAt(index);
|
|
82
|
+
if (code === SEMI)
|
|
83
|
+
continue parameter;
|
|
84
|
+
if (code === EQ) {
|
|
85
|
+
const keyEnd = trailingOWS(header, keyStart, index);
|
|
86
|
+
const key = header.slice(keyStart, keyEnd).toLowerCase();
|
|
87
|
+
index = skipOWS(header, index + 1, len);
|
|
88
|
+
if (index < len && header.charCodeAt(index) === DQUOTE) {
|
|
89
|
+
index++;
|
|
90
|
+
let value = "";
|
|
91
|
+
while (index < len) {
|
|
92
|
+
const code = header.charCodeAt(index++);
|
|
93
|
+
if (code === DQUOTE) {
|
|
94
|
+
index = skipValue(header, index, len);
|
|
95
|
+
if (parameters[key] === undefined)
|
|
96
|
+
parameters[key] = value;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
if (code === BSLASH && index < len) {
|
|
100
|
+
value += header[index++];
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
value += String.fromCharCode(code);
|
|
104
|
+
}
|
|
105
|
+
continue parameter;
|
|
106
|
+
}
|
|
107
|
+
const valueStart = index;
|
|
108
|
+
index = skipValue(header, index, len);
|
|
109
|
+
if (parameters[key] === undefined) {
|
|
110
|
+
const valueEnd = trailingOWS(header, valueStart, index);
|
|
111
|
+
parameters[key] = header.slice(valueStart, valueEnd);
|
|
112
|
+
}
|
|
113
|
+
continue parameter;
|
|
114
|
+
}
|
|
115
|
+
index++;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return parameters;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Skip over characters until a semicolon.
|
|
122
|
+
*/
|
|
123
|
+
function skipValue(str, index, len) {
|
|
124
|
+
while (index < len) {
|
|
125
|
+
const char = str.charCodeAt(index);
|
|
126
|
+
if (char === SEMI)
|
|
127
|
+
break;
|
|
128
|
+
index++;
|
|
129
|
+
}
|
|
130
|
+
return index;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Skip optional whitespace (OWS) in an HTTP header value.
|
|
134
|
+
*
|
|
135
|
+
* OWS is defined in RFC 9110 sec 5.6.3 as SP (" ") or HTAB ("\t").
|
|
136
|
+
*/
|
|
137
|
+
function skipOWS(header, index, len) {
|
|
138
|
+
while (index < len) {
|
|
139
|
+
const char = header.charCodeAt(index);
|
|
140
|
+
if (char !== SP && char !== HTAB)
|
|
141
|
+
break;
|
|
142
|
+
index++;
|
|
143
|
+
}
|
|
144
|
+
return index;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Trim optional whitespace (OWS) from the end of a substring.
|
|
148
|
+
*
|
|
149
|
+
* OWS is defined in RFC 9110 sec 5.6.3 as SP (" ") or HTAB ("\t").
|
|
150
|
+
*/
|
|
151
|
+
function trailingOWS(header, start, end) {
|
|
152
|
+
while (end > start) {
|
|
153
|
+
const char = header.charCodeAt(end - 1);
|
|
154
|
+
if (char !== SP && char !== HTAB)
|
|
155
|
+
break;
|
|
156
|
+
end--;
|
|
157
|
+
}
|
|
158
|
+
return end;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Serialize a parameter value.
|
|
162
|
+
*/
|
|
163
|
+
function qstring(str) {
|
|
164
|
+
if (TOKEN_REGEXP.test(str))
|
|
165
|
+
return str;
|
|
166
|
+
if (TEXT_REGEXP.test(str))
|
|
167
|
+
return `"${str.replace(QUOTE_REGEXP, "\\$&")}"`;
|
|
168
|
+
throw new TypeError(`Invalid parameter value: ${str}`);
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAwCH,wBAoBC;AAYD,sBAcC;AApFD,MAAM,WAAW,GAAG,uCAAuC,CAAC;AAC5D,MAAM,YAAY,GAAG,+BAA+B,CAAC;AAErD;;GAEG;AACH,MAAM,YAAY,GAAG,QAAQ,CAAC;AAE9B;;;;;;GAMG;AACH,MAAM,WAAW,GACf,4DA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,IAAI,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,CAAC;IACvC,IAAI,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC,GAAG,CAAC;IAE3E,MAAM,IAAI,SAAS,CAAC,4BAA4B,GAAG,EAAE,CAAC,CAAC;AACzD,CAAC","sourcesContent":["/*!\n * content-type\n * Copyright(c) 2015 Douglas Christopher Wilson\n * MIT Licensed\n */\n\nconst TEXT_REGEXP = /^[\\u0009\\u0020-\\u007e\\u0080-\\u00ff]*$/;\nconst TOKEN_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;\n\n/**\n * RegExp to match chars that must be quoted-pair in RFC 9110 sec 5.6.4\n */\nconst QUOTE_REGEXP = /[\\\\\"]/g;\n\n/**\n * RegExp to match type in RFC 9110 sec 8.3.1\n *\n * media-type = type \"/\" subtype\n * type = token\n * subtype = token\n */\nconst TYPE_REGEXP =\n /^[!#$%&'*+.^_`|~0-9A-Za-z-]+\\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;\n\n/**\n * Null object perf optimization. Faster than `Object.create(null)` and `{ __proto__: null }`.\n */\nconst NullObject = /* @__PURE__ */ (() => {\n const C = function () {};\n C.prototype = Object.create(null);\n return C;\n})() as unknown as { new (): any };\n\n/**\n * The content type object contains a type string and optional parameters.\n */\nexport interface ContentType {\n type: string;\n parameters: Record<string, string>;\n}\n\n/**\n * Format an object into a `Content-Type` header.\n */\nexport function format(obj: Partial<ContentType>): string {\n const { type, parameters } = obj;\n\n if (!type || !TYPE_REGEXP.test(type)) {\n throw new TypeError(`Invalid type: ${type}`);\n }\n\n let result = type;\n\n if (parameters) {\n for (const param of Object.keys(parameters)) {\n if (!TOKEN_REGEXP.test(param)) {\n throw new TypeError(`Invalid parameter name: ${param}`);\n }\n\n result += `; ${param}=${qstring(parameters[param])}`;\n }\n }\n\n return result;\n}\n\n/**\n * Options for parsing a `Content-Type` header.\n */\nexport interface ParseOptions {\n parameters?: boolean;\n}\n\n/**\n * Parse a `Content-Type` header.\n */\nexport function parse(header: string, options?: ParseOptions): ContentType {\n const len = header.length;\n let index = skipOWS(header, 0, len);\n\n const valueStart = index;\n index = skipValue(header, index, len);\n const valueEnd = trailingOWS(header, valueStart, index);\n const type = header.slice(valueStart, valueEnd).toLowerCase();\n const parameters =\n options?.parameters === false\n ? new NullObject()\n : parseParameters(header, index, len);\n\n return { type, parameters };\n}\n\nconst SP = 32; // \" \"\nconst HTAB = 9; // \"\\t\"\nconst SEMI = 59; // \";\"\nconst EQ = 61; // \"=\"\nconst DQUOTE = 34; // '\"'\nconst BSLASH = 92; // \"\\\\\"\n\n/**\n * Parses the parameters of a `Content-Type` header starting at the given index.\n */\nfunction parseParameters(\n header: string,\n index: number,\n len: number,\n): Record<string, string> {\n const parameters: Record<string, string> = new NullObject();\n\n parameter: while (index < len) {\n index = skipOWS(header, index + 1 /* Skip over ; */, len);\n\n const keyStart = index;\n\n while (index < len) {\n const code = header.charCodeAt(index);\n if (code === SEMI) continue parameter;\n\n if (code === EQ) {\n const keyEnd = trailingOWS(header, keyStart, index);\n const key = header.slice(keyStart, keyEnd).toLowerCase();\n\n index = skipOWS(header, index + 1, len);\n\n if (index < len && header.charCodeAt(index) === DQUOTE) {\n index++;\n\n let value = \"\";\n while (index < len) {\n const code = header.charCodeAt(index++);\n if (code === DQUOTE) {\n index = skipValue(header, index, len);\n if (parameters[key] === undefined) parameters[key] = value;\n break;\n }\n\n if (code === BSLASH && index < len) {\n value += header[index++];\n continue;\n }\n\n value += String.fromCharCode(code);\n }\n\n continue parameter;\n }\n\n const valueStart = index;\n index = skipValue(header, index, len);\n\n if (parameters[key] === undefined) {\n const valueEnd = trailingOWS(header, valueStart, index);\n parameters[key] = header.slice(valueStart, valueEnd);\n }\n\n continue parameter;\n }\n\n index++;\n }\n }\n\n return parameters;\n}\n\n/**\n * Skip over characters until a semicolon.\n */\nfunction skipValue(str: string, index: number, len: number): number {\n while (index < len) {\n const char = str.charCodeAt(index);\n if (char === SEMI) break;\n index++;\n }\n return index;\n}\n\n/**\n * Skip optional whitespace (OWS) in an HTTP header value.\n *\n * OWS is defined in RFC 9110 sec 5.6.3 as SP (\" \") or HTAB (\"\\t\").\n */\nfunction skipOWS(header: string, index: number, len: number): number {\n while (index < len) {\n const char = header.charCodeAt(index);\n if (char !== SP && char !== HTAB) break;\n index++;\n }\n return index;\n}\n\n/**\n * Trim optional whitespace (OWS) from the end of a substring.\n *\n * OWS is defined in RFC 9110 sec 5.6.3 as SP (\" \") or HTAB (\"\\t\").\n */\nfunction trailingOWS(header: string, start: number, end: number): number {\n while (end > start) {\n const char = header.charCodeAt(end - 1);\n if (char !== SP && char !== HTAB) break;\n end--;\n }\n return end;\n}\n\n/**\n * Serialize a parameter value.\n */\nfunction qstring(str: string): string {\n if (TOKEN_REGEXP.test(str)) return str;\n if (TEXT_REGEXP.test(str)) return `\"${str.replace(QUOTE_REGEXP, \"\\\\$&\")}\"`;\n\n throw new TypeError(`Invalid parameter value: ${str}`);\n}\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "content-type",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Create and parse HTTP Content-Type header",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"content-type",
|
|
7
|
+
"http",
|
|
8
|
+
"req",
|
|
9
|
+
"res",
|
|
10
|
+
"rfc7231",
|
|
11
|
+
"rfc9110"
|
|
12
|
+
],
|
|
13
|
+
"repository": "jshttp/content-type",
|
|
14
|
+
"funding": {
|
|
15
|
+
"type": "opencollective",
|
|
16
|
+
"url": "https://opencollective.com/express"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "Douglas Christopher Wilson <doug@somethingdoug.com>",
|
|
20
|
+
"type": "commonjs",
|
|
21
|
+
"exports": "./dist/index.js",
|
|
22
|
+
"main": "./dist/index.js",
|
|
23
|
+
"typings": "./dist/index.d.ts",
|
|
24
|
+
"files": [
|
|
25
|
+
"dist/"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"bench": "vitest bench",
|
|
29
|
+
"build": "ts-scripts build",
|
|
30
|
+
"format": "ts-scripts format",
|
|
31
|
+
"prepare": "ts-scripts install && npm run build",
|
|
32
|
+
"specs": "ts-scripts specs",
|
|
33
|
+
"test": "ts-scripts test"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@borderless/ts-scripts": "^0.15.0",
|
|
37
|
+
"@vitest/coverage-v8": "^3.0.5",
|
|
38
|
+
"typescript": "^5.7.3",
|
|
39
|
+
"vitest": "^3.2.4"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=18"
|
|
43
|
+
},
|
|
44
|
+
"ts-scripts": {
|
|
45
|
+
"dist": [
|
|
46
|
+
"dist"
|
|
47
|
+
],
|
|
48
|
+
"project": [
|
|
49
|
+
"tsconfig.build.json"
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
}
|