root / HServer / 00.Server / 00.Program / node_modules / cookie-parser / README.md
이력 | 보기 | 이력해설 | 다운로드 (3.45 KB)
1 | 39 | HKM | # cookie-parser |
---|---|---|---|
2 | |||
3 | [![NPM Version][npm-image]][npm-url] |
||
4 | [![NPM Downloads][downloads-image]][downloads-url] |
||
5 | [![Node.js Version][node-version-image]][node-version-url] |
||
6 | [![Build Status][travis-image]][travis-url] |
||
7 | [![Test Coverage][coveralls-image]][coveralls-url] |
||
8 | |||
9 | Parse `Cookie` header and populate `req.cookies` with an object keyed by the cookie |
||
10 | names. Optionally you may enable signed cookie support by passing a `secret` string, |
||
11 | which assigns `req.secret` so it may be used by other middleware. |
||
12 | |||
13 | ## Installation |
||
14 | |||
15 | ```sh |
||
16 | $ npm install cookie-parser |
||
17 | ``` |
||
18 | |||
19 | ## API |
||
20 | |||
21 | ```js |
||
22 | var express = require('express') |
||
23 | var cookieParser = require('cookie-parser') |
||
24 | |||
25 | var app = express() |
||
26 | app.use(cookieParser()) |
||
27 | ``` |
||
28 | |||
29 | ### cookieParser(secret, options) |
||
30 | |||
31 | - `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. |
||
32 | - `options` an object that is passed to `cookie.parse` as the second option. See [cookie](https://www.npmjs.org/package/cookie) for more information. |
||
33 | - `decode` a function to decode the value of the cookie |
||
34 | |||
35 | ### cookieParser.JSONCookie(str) |
||
36 | |||
37 | 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. |
||
38 | |||
39 | ### cookieParser.JSONCookies(cookies) |
||
40 | |||
41 | Given an object, this will iterate over the keys and call `JSONCookie` on each value. This will return the same object passed in. |
||
42 | |||
43 | ### cookieParser.signedCookie(str, secret) |
||
44 | |||
45 | 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, otherwise it will return the passed value. |
||
46 | |||
47 | 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. |
||
48 | |||
49 | ### cookieParser.signedCookies(cookies, secret) |
||
50 | |||
51 | 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. |
||
52 | |||
53 | 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. |
||
54 | |||
55 | ## Example |
||
56 | |||
57 | ```js |
||
58 | var express = require('express') |
||
59 | var cookieParser = require('cookie-parser') |
||
60 | |||
61 | var app = express() |
||
62 | app.use(cookieParser()) |
||
63 | |||
64 | app.get('/', function(req, res) { |
||
65 | console.log('Cookies: ', req.cookies) |
||
66 | }) |
||
67 | |||
68 | app.listen(8080) |
||
69 | |||
70 | // curl command that sends an HTTP request with two cookies |
||
71 | // curl http://127.0.0.1:8080 --cookie "Cho=Kim;Greet=Hello" |
||
72 | ``` |
||
73 | |||
74 | ### [MIT Licensed](LICENSE) |
||
75 | |||
76 | [npm-image]: https://img.shields.io/npm/v/cookie-parser.svg |
||
77 | [npm-url]: https://npmjs.org/package/cookie-parser |
||
78 | [node-version-image]: https://img.shields.io/node/v/cookie-parser.svg |
||
79 | [node-version-url]: https://nodejs.org/en/download |
||
80 | [travis-image]: https://img.shields.io/travis/expressjs/cookie-parser/master.svg |
||
81 | [travis-url]: https://travis-ci.org/expressjs/cookie-parser |
||
82 | [coveralls-image]: https://img.shields.io/coveralls/expressjs/cookie-parser/master.svg |
||
83 | [coveralls-url]: https://coveralls.io/r/expressjs/cookie-parser?branch=master |
||
84 | [downloads-image]: https://img.shields.io/npm/dm/cookie-parser.svg |
||
85 | [downloads-url]: https://npmjs.org/package/cookie-parser |