You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Parse `Cookie` header and populate `req.cookies` with an object keyed by the cookie
9
-
names. Optionally you may enable signed cookie support by passing a `secret` string,
10
-
which assigns `req.secret` so it may be used by other middleware.
8
+
Parse `Cookie` header and populate `req.cookies` with an object keyed by the
9
+
cookie names. Optionally you may enable signed cookie support by passing a
10
+
`secret` string, which assigns `req.secret` so it may be used by other
11
+
middleware.
11
12
12
13
## Installation
13
14
@@ -27,29 +28,45 @@ app.use(cookieParser())
27
28
28
29
### cookieParser(secret, options)
29
30
30
-
-`secret` a string or array used for signing cookies. This is optional and if not specified, will not parse signed cookies. If a string is provided, this is used as the secret. If an array is provided, an attempt will be made to unsign the cookie with each secret in order.
31
-
-`options` an object that is passed to `cookie.parse` as the second option. See [cookie](https://www.npmjs.org/package/cookie) for more information.
31
+
-`secret` a string or array used for signing cookies. This is optional and if
32
+
not specified, will not parse signed cookies. If a string is provided, this
33
+
is used as the secret. If an array is provided, an attempt will be made to
34
+
unsign the cookie with each secret in order.
35
+
-`options` an object that is passed to `cookie.parse` as the second option. Se
36
+
[cookie](https://www.npmjs.org/package/cookie) for more information.
32
37
-`decode` a function to decode the value of the cookie
33
38
34
39
### cookieParser.JSONCookie(str)
35
40
36
-
Parse a cookie value as a JSON cookie. This will return the parsed JSON value if it was a JSON cookie, otherwise, it will return the passed value.
41
+
Parse a cookie value as a JSON cookie. This will return the parsed JSON value
42
+
if it was a JSON cookie, otherwise, it will return the passed value.
37
43
38
44
### cookieParser.JSONCookies(cookies)
39
45
40
-
Given an object, this will iterate over the keys and call `JSONCookie` on each value, replacing the original value with the parsed value. This returns the same object that was passed in.
46
+
Given an object, this will iterate over the keys and call `JSONCookie` on each
47
+
value, replacing the original value with the parsed value. This returns the
48
+
same object that was passed in.
41
49
42
50
### cookieParser.signedCookie(str, secret)
43
51
44
-
Parse a cookie value as a signed cookie. This will return the parsed unsigned value if it was a signed cookie and the signature was valid. If the value was not signed, the original value is returned. If the value was signed but the signature could not be validated, `false` is returned.
52
+
Parse a cookie value as a signed cookie. This will return the parsed unsigned
53
+
value if it was a signed cookie and the signature was valid. If the value was
54
+
not signed, the original value is returned. If the value was signed but the
55
+
signature could not be validated, `false` is returned.
45
56
46
-
The `secret` argument can be an array or string. If a string is provided, this is used as the secret. If an array is provided, an attempt will be made to unsign the cookie with each secret in order.
57
+
The `secret` argument can be an array or string. If a string is provided, this
58
+
is used as the secret. If an array is provided, an attempt will be made to
59
+
unsign the cookie with each secret in order.
47
60
48
61
### cookieParser.signedCookies(cookies, secret)
49
62
50
-
Given an object, this will iterate over the keys and check if any value is a signed cookie. If it is a signed cookie and the signature is valid, the key will be deleted from the object and added to the new object that is returned.
63
+
Given an object, this will iterate over the keys and check if any value is a
64
+
signed cookie. If it is a signed cookie and the signature is valid, the key
65
+
will be deleted from the object and added to the new object that is returned.
51
66
52
-
The `secret` argument can be an array or string. If a string is provided, this is used as the secret. If an array is provided, an attempt will be made to unsign the cookie with each secret in order.
67
+
The `secret` argument can be an array or string. If a string is provided, this
68
+
is used as the secret. If an array is provided, an attempt will be made to
0 commit comments