-
Notifications
You must be signed in to change notification settings - Fork 16
/
body-parser.express.txt
51 lines (40 loc) · 3.69 KB
/
body-parser.express.txt
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
BODY-PARSER
VERSION ==> #2.0.0-beta.2
BODY-PARSER.*([OPTS])->MDWR #Express MIDWR:
# - same signature FUNC(REQ, RES, NEXT)
# - but actually does not depend on Express being loaded, nor use RES
#Sets REQ.body using HTTP request payload
# - undefined if none
BODY-PARSER.urlencoded([OPTS])#As an OBJ, for Content-Type [C] "application/x-www-form-urlencoded"
BODY-PARSER.json([OPTS]) #As an OBJ, for "application/json"
BODY-PARSER.text([OPTS]) #As a STR, for "text/plain"
BODY-PARSER.raw([OPTS]) #As a BUFFER, for "application/octet-stream"
OPTS.type #MIME[_ARR][(REQ)] (def: depends on type)
#Only applies to requests with that MIME
#Uses TYPE-IS(REQ, MIME[_ARR]) (see its doc)
OPTS.inflate #BOOL (def: true): automatically decompress gzip|deflate encodings
OPTS.limit #NUM (def: '100kb') (uses BYTES parsing, see its doc): max request size
OPTS.verify #FUNC(REQ, RES, BUFFER, ENCODING): should throw error if input is not proper
(only urlencoded())
OPTS.extended #BOOL (def: true):
# - supports VAR[VAR2]=VAL&...
# - by using QS instead of QUERYSTRING, with OPTS: arrayLimit OPTS.limit (max 100),
# parameterLimit OPTS.limit, depth Infinity
OPTS.parameterLimit #NUM (def: 1000): max number of parameters
(only json())
OPTS.strict #BOOL (def: true): only parses OBJ|ARR
OPTS.reviver #FUNC passed to JSON.parse(..., FUNC)
(only text())
OPTS.defaultCharset #'CHARSET' (def: "utf-8")
ERRORS ==> #next(ERROR):
# - 400 (ERROR.type "request.aborted") if client aborted the request
# - 400 (ERROR.type "request.size.invalid") if Content-Length [C] does not match
# - 400 (ERROR.type "entity.parse.failed") if parsing failed
# - 403 on wrong verify()
# - 413 (ERROR.type "entity.too.large") if above OPTS.limit
# - 413 (ERROR.type "parameters.too.many") if above OPTS.parameterLimit
# - 415 (ERROR.type "encoding.unsupported") on unsupported ENCODING,
# or if OPTS.inflate false and should decompress, or if unsupported encoding
# - 415 (ERROR.type "charset.unsupported") on unsupported charset