es6-crawler-detect 3.1.3 → 3.2.0
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/.babelrc +18 -17
- package/.eslintignore +6 -0
- package/.eslintrc.json +30 -0
- package/.github/FUNDING.yml +12 -12
- package/.github/ISSUE_TEMPLATE/bug_report.md +41 -38
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -20
- package/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +29 -0
- package/.prettierrc.json +5 -0
- package/CODE_OF_CONDUCT.md +76 -76
- package/LICENSE +21 -21
- package/README.md +103 -93
- package/dist/main.bundle.js +1 -1
- package/example/node/dist/crawler.min.js +1 -1
- package/example/node/index.html +21 -21
- package/example/node/node_modules/.bin/mime +15 -0
- package/example/node/node_modules/.bin/mime.cmd +7 -0
- package/example/node/node_modules/.yarn-integrity +67 -0
- package/example/node/node_modules/accepts/HISTORY.md +236 -0
- package/example/node/node_modules/accepts/LICENSE +23 -0
- package/example/node/node_modules/accepts/README.md +142 -0
- package/example/node/node_modules/accepts/index.js +238 -0
- package/example/node/node_modules/accepts/package.json +47 -0
- package/example/node/node_modules/array-flatten/LICENSE +21 -0
- package/example/node/node_modules/array-flatten/README.md +43 -0
- package/example/node/node_modules/array-flatten/array-flatten.js +64 -0
- package/example/node/node_modules/array-flatten/package.json +39 -0
- package/example/node/node_modules/body-parser/HISTORY.md +624 -0
- package/example/node/node_modules/body-parser/LICENSE +23 -0
- package/example/node/node_modules/body-parser/README.md +456 -0
- package/example/node/node_modules/body-parser/index.js +157 -0
- package/example/node/node_modules/body-parser/lib/read.js +181 -0
- package/example/node/node_modules/body-parser/lib/types/json.js +230 -0
- package/example/node/node_modules/body-parser/lib/types/raw.js +101 -0
- package/example/node/node_modules/body-parser/lib/types/text.js +121 -0
- package/example/node/node_modules/body-parser/lib/types/urlencoded.js +284 -0
- package/example/node/node_modules/body-parser/package.json +52 -0
- package/example/node/node_modules/bytes/History.md +92 -0
- package/example/node/node_modules/bytes/LICENSE +23 -0
- package/example/node/node_modules/bytes/Readme.md +152 -0
- package/example/node/node_modules/bytes/index.js +166 -0
- package/example/node/node_modules/bytes/package.json +42 -0
- package/example/node/node_modules/content-disposition/HISTORY.md +60 -0
- package/example/node/node_modules/content-disposition/LICENSE +22 -0
- package/example/node/node_modules/content-disposition/README.md +142 -0
- package/example/node/node_modules/content-disposition/index.js +458 -0
- package/example/node/node_modules/content-disposition/package.json +44 -0
- package/example/node/node_modules/content-type/HISTORY.md +24 -0
- package/example/node/node_modules/content-type/LICENSE +22 -0
- package/example/node/node_modules/content-type/README.md +92 -0
- package/example/node/node_modules/content-type/index.js +222 -0
- package/example/node/node_modules/content-type/package.json +40 -0
- package/example/node/node_modules/cookie/HISTORY.md +128 -0
- package/example/node/node_modules/cookie/LICENSE +24 -0
- package/example/node/node_modules/cookie/README.md +257 -0
- package/example/node/node_modules/cookie/index.js +202 -0
- package/example/node/node_modules/cookie/package.json +40 -0
- package/example/node/node_modules/cookie-signature/History.md +38 -0
- package/example/node/node_modules/cookie-signature/Readme.md +42 -0
- package/example/node/node_modules/cookie-signature/index.js +51 -0
- package/example/node/node_modules/cookie-signature/package.json +18 -0
- package/example/node/node_modules/debug/.coveralls.yml +1 -0
- package/example/node/node_modules/debug/.eslintrc +11 -0
- package/example/node/node_modules/debug/.travis.yml +14 -0
- package/example/node/node_modules/debug/CHANGELOG.md +362 -0
- package/example/node/node_modules/debug/LICENSE +19 -0
- package/example/node/node_modules/debug/Makefile +50 -0
- package/example/node/node_modules/debug/README.md +312 -0
- package/example/node/node_modules/debug/component.json +19 -0
- package/example/node/node_modules/debug/karma.conf.js +70 -0
- package/example/node/node_modules/debug/node.js +1 -0
- package/example/node/node_modules/debug/package.json +49 -0
- package/example/node/node_modules/debug/src/browser.js +185 -0
- package/example/node/node_modules/debug/src/debug.js +202 -0
- package/example/node/node_modules/debug/src/index.js +10 -0
- package/example/node/node_modules/debug/src/inspector-log.js +15 -0
- package/example/node/node_modules/debug/src/node.js +248 -0
- package/example/node/node_modules/depd/History.md +96 -0
- package/example/node/node_modules/depd/LICENSE +22 -0
- package/example/node/node_modules/depd/Readme.md +280 -0
- package/example/node/node_modules/depd/index.js +522 -0
- package/example/node/node_modules/depd/lib/browser/index.js +77 -0
- package/example/node/node_modules/depd/lib/compat/callsite-tostring.js +103 -0
- package/example/node/node_modules/depd/lib/compat/event-listener-count.js +22 -0
- package/example/node/node_modules/depd/lib/compat/index.js +79 -0
- package/example/node/node_modules/depd/package.json +41 -0
- package/example/node/node_modules/destroy/LICENSE +22 -0
- package/example/node/node_modules/destroy/README.md +60 -0
- package/example/node/node_modules/destroy/index.js +75 -0
- package/example/node/node_modules/destroy/package.json +37 -0
- package/example/node/node_modules/ee-first/LICENSE +22 -0
- package/example/node/node_modules/ee-first/README.md +80 -0
- package/example/node/node_modules/ee-first/index.js +95 -0
- package/example/node/node_modules/ee-first/package.json +29 -0
- package/example/node/node_modules/encodeurl/HISTORY.md +14 -0
- package/example/node/node_modules/encodeurl/LICENSE +22 -0
- package/example/node/node_modules/encodeurl/README.md +128 -0
- package/example/node/node_modules/encodeurl/index.js +60 -0
- package/example/node/node_modules/encodeurl/package.json +40 -0
- package/example/node/node_modules/escape-html/LICENSE +24 -0
- package/example/node/node_modules/escape-html/Readme.md +43 -0
- package/example/node/node_modules/escape-html/index.js +78 -0
- package/example/node/node_modules/escape-html/package.json +24 -0
- package/example/node/node_modules/etag/HISTORY.md +83 -0
- package/example/node/node_modules/etag/LICENSE +22 -0
- package/example/node/node_modules/etag/README.md +159 -0
- package/example/node/node_modules/etag/index.js +131 -0
- package/example/node/node_modules/etag/package.json +47 -0
- package/example/node/node_modules/express/History.md +3510 -0
- package/example/node/node_modules/express/LICENSE +24 -0
- package/example/node/node_modules/express/Readme.md +158 -0
- package/example/node/node_modules/express/index.js +11 -0
- package/example/node/node_modules/express/lib/application.js +644 -0
- package/example/node/node_modules/express/lib/express.js +116 -0
- package/example/node/node_modules/express/lib/middleware/init.js +43 -0
- package/example/node/node_modules/express/lib/middleware/query.js +47 -0
- package/example/node/node_modules/express/lib/request.js +525 -0
- package/example/node/node_modules/express/lib/response.js +1147 -0
- package/example/node/node_modules/express/lib/router/index.js +668 -0
- package/example/node/node_modules/express/lib/router/layer.js +181 -0
- package/example/node/node_modules/express/lib/router/route.js +216 -0
- package/example/node/node_modules/express/lib/utils.js +302 -0
- package/example/node/node_modules/express/lib/view.js +182 -0
- package/example/node/node_modules/express/package.json +99 -0
- package/example/node/node_modules/finalhandler/HISTORY.md +187 -0
- package/example/node/node_modules/finalhandler/LICENSE +22 -0
- package/example/node/node_modules/finalhandler/README.md +148 -0
- package/example/node/node_modules/finalhandler/index.js +331 -0
- package/example/node/node_modules/finalhandler/package.json +45 -0
- package/example/node/node_modules/forwarded/HISTORY.md +21 -0
- package/example/node/node_modules/forwarded/LICENSE +22 -0
- package/example/node/node_modules/forwarded/README.md +57 -0
- package/example/node/node_modules/forwarded/index.js +90 -0
- package/example/node/node_modules/forwarded/package.json +45 -0
- package/example/node/node_modules/fresh/HISTORY.md +70 -0
- package/example/node/node_modules/fresh/LICENSE +23 -0
- package/example/node/node_modules/fresh/README.md +119 -0
- package/example/node/node_modules/fresh/index.js +137 -0
- package/example/node/node_modules/fresh/package.json +46 -0
- package/example/node/node_modules/http-errors/HISTORY.md +165 -0
- package/example/node/node_modules/http-errors/LICENSE +23 -0
- package/example/node/node_modules/http-errors/README.md +169 -0
- package/example/node/node_modules/http-errors/index.js +299 -0
- package/example/node/node_modules/http-errors/package.json +49 -0
- package/example/node/node_modules/iconv-lite/Changelog.md +162 -0
- package/example/node/node_modules/iconv-lite/LICENSE +21 -0
- package/example/node/node_modules/iconv-lite/README.md +156 -0
- package/example/node/node_modules/iconv-lite/encodings/dbcs-codec.js +555 -0
- package/example/node/node_modules/iconv-lite/encodings/dbcs-data.js +176 -0
- package/example/node/node_modules/iconv-lite/encodings/index.js +22 -0
- package/example/node/node_modules/iconv-lite/encodings/internal.js +188 -0
- package/example/node/node_modules/iconv-lite/encodings/sbcs-codec.js +72 -0
- package/example/node/node_modules/iconv-lite/encodings/sbcs-data-generated.js +451 -0
- package/example/node/node_modules/iconv-lite/encodings/sbcs-data.js +174 -0
- package/example/node/node_modules/iconv-lite/encodings/tables/big5-added.json +122 -0
- package/example/node/node_modules/iconv-lite/encodings/tables/cp936.json +264 -0
- package/example/node/node_modules/iconv-lite/encodings/tables/cp949.json +273 -0
- package/example/node/node_modules/iconv-lite/encodings/tables/cp950.json +177 -0
- package/example/node/node_modules/iconv-lite/encodings/tables/eucjp.json +182 -0
- package/example/node/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json +1 -0
- package/example/node/node_modules/iconv-lite/encodings/tables/gbk-added.json +55 -0
- package/example/node/node_modules/iconv-lite/encodings/tables/shiftjis.json +125 -0
- package/example/node/node_modules/iconv-lite/encodings/utf16.js +177 -0
- package/example/node/node_modules/iconv-lite/encodings/utf7.js +290 -0
- package/example/node/node_modules/iconv-lite/lib/bom-handling.js +52 -0
- package/example/node/node_modules/iconv-lite/lib/extend-node.js +217 -0
- package/example/node/node_modules/iconv-lite/lib/index.d.ts +24 -0
- package/example/node/node_modules/iconv-lite/lib/index.js +153 -0
- package/example/node/node_modules/iconv-lite/lib/streams.js +121 -0
- package/example/node/node_modules/iconv-lite/package.json +46 -0
- package/example/node/node_modules/inherits/LICENSE +16 -0
- package/example/node/node_modules/inherits/README.md +42 -0
- package/example/node/node_modules/inherits/inherits.js +9 -0
- package/example/node/node_modules/inherits/inherits_browser.js +27 -0
- package/example/node/node_modules/inherits/package.json +29 -0
- package/example/node/node_modules/ipaddr.js/LICENSE +19 -0
- package/example/node/node_modules/ipaddr.js/README.md +233 -0
- package/example/node/node_modules/ipaddr.js/ipaddr.min.js +1 -0
- package/example/node/node_modules/ipaddr.js/lib/ipaddr.js +673 -0
- package/example/node/node_modules/ipaddr.js/lib/ipaddr.js.d.ts +68 -0
- package/example/node/node_modules/ipaddr.js/package.json +35 -0
- package/example/node/node_modules/media-typer/HISTORY.md +22 -0
- package/example/node/node_modules/media-typer/LICENSE +22 -0
- package/example/node/node_modules/media-typer/README.md +81 -0
- package/example/node/node_modules/media-typer/index.js +270 -0
- package/example/node/node_modules/media-typer/package.json +26 -0
- package/example/node/node_modules/merge-descriptors/HISTORY.md +21 -0
- package/example/node/node_modules/merge-descriptors/LICENSE +23 -0
- package/example/node/node_modules/merge-descriptors/README.md +48 -0
- package/example/node/node_modules/merge-descriptors/index.js +60 -0
- package/example/node/node_modules/merge-descriptors/package.json +32 -0
- package/example/node/node_modules/methods/HISTORY.md +29 -0
- package/example/node/node_modules/methods/LICENSE +24 -0
- package/example/node/node_modules/methods/README.md +51 -0
- package/example/node/node_modules/methods/index.js +69 -0
- package/example/node/node_modules/methods/package.json +36 -0
- package/example/node/node_modules/mime/CHANGELOG.md +164 -0
- package/example/node/node_modules/mime/LICENSE +21 -0
- package/example/node/node_modules/mime/README.md +90 -0
- package/example/node/node_modules/mime/cli.js +8 -0
- package/example/node/node_modules/mime/mime.js +108 -0
- package/example/node/node_modules/mime/package.json +44 -0
- package/example/node/node_modules/mime/src/build.js +53 -0
- package/example/node/node_modules/mime/src/test.js +60 -0
- package/example/node/node_modules/mime/types.json +1 -0
- package/example/node/node_modules/mime-db/HISTORY.md +499 -0
- package/example/node/node_modules/mime-db/LICENSE +22 -0
- package/example/node/node_modules/mime-db/README.md +100 -0
- package/example/node/node_modules/mime-db/db.json +8471 -0
- package/example/node/node_modules/mime-db/index.js +11 -0
- package/example/node/node_modules/mime-db/package.json +59 -0
- package/example/node/node_modules/mime-types/HISTORY.md +388 -0
- package/example/node/node_modules/mime-types/LICENSE +23 -0
- package/example/node/node_modules/mime-types/README.md +113 -0
- package/example/node/node_modules/mime-types/index.js +188 -0
- package/example/node/node_modules/mime-types/package.json +44 -0
- package/example/node/node_modules/ms/index.js +152 -0
- package/example/node/node_modules/ms/license.md +21 -0
- package/example/node/node_modules/ms/package.json +37 -0
- package/example/node/node_modules/ms/readme.md +51 -0
- package/example/node/node_modules/negotiator/HISTORY.md +103 -0
- package/example/node/node_modules/negotiator/LICENSE +24 -0
- package/example/node/node_modules/negotiator/README.md +203 -0
- package/example/node/node_modules/negotiator/index.js +124 -0
- package/example/node/node_modules/negotiator/lib/charset.js +169 -0
- package/example/node/node_modules/negotiator/lib/encoding.js +184 -0
- package/example/node/node_modules/negotiator/lib/language.js +179 -0
- package/example/node/node_modules/negotiator/lib/mediaType.js +294 -0
- package/example/node/node_modules/negotiator/package.json +42 -0
- package/example/node/node_modules/on-finished/HISTORY.md +88 -0
- package/example/node/node_modules/on-finished/LICENSE +23 -0
- package/example/node/node_modules/on-finished/README.md +154 -0
- package/example/node/node_modules/on-finished/index.js +196 -0
- package/example/node/node_modules/on-finished/package.json +31 -0
- package/example/node/node_modules/parseurl/HISTORY.md +58 -0
- package/example/node/node_modules/parseurl/LICENSE +24 -0
- package/example/node/node_modules/parseurl/README.md +133 -0
- package/example/node/node_modules/parseurl/index.js +158 -0
- package/example/node/node_modules/parseurl/package.json +40 -0
- package/example/node/node_modules/path-to-regexp/History.md +36 -0
- package/example/node/node_modules/path-to-regexp/LICENSE +21 -0
- package/example/node/node_modules/path-to-regexp/Readme.md +35 -0
- package/example/node/node_modules/path-to-regexp/index.js +129 -0
- package/example/node/node_modules/path-to-regexp/package.json +30 -0
- package/example/node/node_modules/proxy-addr/HISTORY.md +161 -0
- package/example/node/node_modules/proxy-addr/LICENSE +22 -0
- package/example/node/node_modules/proxy-addr/README.md +139 -0
- package/example/node/node_modules/proxy-addr/index.js +327 -0
- package/example/node/node_modules/proxy-addr/package.json +47 -0
- package/example/node/node_modules/qs/.editorconfig +39 -0
- package/example/node/node_modules/qs/.eslintignore +2 -0
- package/example/node/node_modules/qs/.eslintrc +35 -0
- package/example/node/node_modules/qs/.github/FUNDING.yml +12 -0
- package/example/node/node_modules/qs/.nycrc +13 -0
- package/example/node/node_modules/qs/CHANGELOG.md +359 -0
- package/example/node/node_modules/qs/LICENSE.md +29 -0
- package/example/node/node_modules/qs/README.md +604 -0
- package/example/node/node_modules/qs/dist/qs.js +832 -0
- package/example/node/node_modules/qs/lib/formats.js +23 -0
- package/example/node/node_modules/qs/lib/index.js +11 -0
- package/example/node/node_modules/qs/lib/parse.js +257 -0
- package/example/node/node_modules/qs/lib/stringify.js +278 -0
- package/example/node/node_modules/qs/lib/utils.js +251 -0
- package/example/node/node_modules/qs/package.json +69 -0
- package/example/node/node_modules/qs/test/parse.js +772 -0
- package/example/node/node_modules/qs/test/stringify.js +793 -0
- package/example/node/node_modules/qs/test/utils.js +136 -0
- package/example/node/node_modules/range-parser/HISTORY.md +56 -0
- package/example/node/node_modules/range-parser/LICENSE +23 -0
- package/example/node/node_modules/range-parser/README.md +84 -0
- package/example/node/node_modules/range-parser/index.js +162 -0
- package/example/node/node_modules/range-parser/package.json +44 -0
- package/example/node/node_modules/raw-body/HISTORY.md +284 -0
- package/example/node/node_modules/raw-body/LICENSE +22 -0
- package/example/node/node_modules/raw-body/README.md +217 -0
- package/example/node/node_modules/raw-body/index.d.ts +87 -0
- package/example/node/node_modules/raw-body/index.js +286 -0
- package/example/node/node_modules/raw-body/package.json +48 -0
- package/example/node/node_modules/safe-buffer/LICENSE +21 -0
- package/example/node/node_modules/safe-buffer/README.md +584 -0
- package/example/node/node_modules/safe-buffer/index.d.ts +187 -0
- package/example/node/node_modules/safe-buffer/index.js +65 -0
- package/example/node/node_modules/safe-buffer/package.json +51 -0
- package/example/node/node_modules/safer-buffer/LICENSE +21 -0
- package/example/node/node_modules/safer-buffer/Porting-Buffer.md +268 -0
- package/example/node/node_modules/safer-buffer/Readme.md +156 -0
- package/example/node/node_modules/safer-buffer/dangerous.js +58 -0
- package/example/node/node_modules/safer-buffer/package.json +34 -0
- package/example/node/node_modules/safer-buffer/safer.js +77 -0
- package/example/node/node_modules/safer-buffer/tests.js +406 -0
- package/example/node/node_modules/send/HISTORY.md +506 -0
- package/example/node/node_modules/send/LICENSE +23 -0
- package/example/node/node_modules/send/README.md +327 -0
- package/example/node/node_modules/send/index.js +1133 -0
- package/example/node/node_modules/send/node_modules/.bin/mime +15 -0
- package/example/node/node_modules/send/node_modules/.bin/mime.cmd +7 -0
- package/example/node/node_modules/send/node_modules/ms/index.js +162 -0
- package/example/node/node_modules/send/node_modules/ms/license.md +21 -0
- package/example/node/node_modules/send/node_modules/ms/package.json +38 -0
- package/example/node/node_modules/send/node_modules/ms/readme.md +59 -0
- package/example/node/node_modules/send/package.json +61 -0
- package/example/node/node_modules/serve-static/HISTORY.md +459 -0
- package/example/node/node_modules/serve-static/LICENSE +25 -0
- package/example/node/node_modules/serve-static/README.md +257 -0
- package/example/node/node_modules/serve-static/index.js +210 -0
- package/example/node/node_modules/serve-static/package.json +42 -0
- package/example/node/node_modules/setprototypeof/LICENSE +13 -0
- package/example/node/node_modules/setprototypeof/README.md +31 -0
- package/example/node/node_modules/setprototypeof/index.d.ts +2 -0
- package/example/node/node_modules/setprototypeof/index.js +17 -0
- package/example/node/node_modules/setprototypeof/package.json +38 -0
- package/example/node/node_modules/setprototypeof/test/index.js +24 -0
- package/example/node/node_modules/statuses/HISTORY.md +65 -0
- package/example/node/node_modules/statuses/LICENSE +23 -0
- package/example/node/node_modules/statuses/README.md +127 -0
- package/example/node/node_modules/statuses/codes.json +66 -0
- package/example/node/node_modules/statuses/index.js +113 -0
- package/example/node/node_modules/statuses/package.json +48 -0
- package/example/node/node_modules/toidentifier/HISTORY.md +9 -0
- package/example/node/node_modules/toidentifier/LICENSE +21 -0
- package/example/node/node_modules/toidentifier/README.md +61 -0
- package/example/node/node_modules/toidentifier/index.js +32 -0
- package/example/node/node_modules/toidentifier/package.json +38 -0
- package/example/node/node_modules/type-is/HISTORY.md +259 -0
- package/example/node/node_modules/type-is/LICENSE +23 -0
- package/example/node/node_modules/type-is/README.md +170 -0
- package/example/node/node_modules/type-is/index.js +266 -0
- package/example/node/node_modules/type-is/package.json +45 -0
- package/example/node/node_modules/unpipe/HISTORY.md +4 -0
- package/example/node/node_modules/unpipe/LICENSE +22 -0
- package/example/node/node_modules/unpipe/README.md +43 -0
- package/example/node/node_modules/unpipe/index.js +69 -0
- package/example/node/node_modules/unpipe/package.json +27 -0
- package/example/node/node_modules/utils-merge/LICENSE +20 -0
- package/example/node/node_modules/utils-merge/README.md +34 -0
- package/example/node/node_modules/utils-merge/index.js +23 -0
- package/example/node/node_modules/utils-merge/package.json +40 -0
- package/example/node/node_modules/vary/HISTORY.md +39 -0
- package/example/node/node_modules/vary/LICENSE +22 -0
- package/example/node/node_modules/vary/README.md +101 -0
- package/example/node/node_modules/vary/index.js +149 -0
- package/example/node/node_modules/vary/package.json +43 -0
- package/example/node/package.json +11 -0
- package/example/node/server.js +21 -15
- package/example/node/yarn.lock +352 -0
- package/package.json +59 -47
- package/src/index.js +15 -10
- package/src/lib/crawler/crawlers.js +1398 -11
- package/src/lib/crawler/exclusions.js +55 -8
- package/src/lib/crawler/headers.js +18 -9
- package/src/lib/crawler/provider.js +6 -8
- package/src/lib/crawler.js +101 -90
- package/test/lib/crawler.test.js +43 -26
- package/webpack.common.js +7 -7
- package/webpack.dev.js +4 -4
- package/webpack.prod.js +8 -9
@@ -0,0 +1,222 @@
|
|
1
|
+
/*!
|
2
|
+
* content-type
|
3
|
+
* Copyright(c) 2015 Douglas Christopher Wilson
|
4
|
+
* MIT Licensed
|
5
|
+
*/
|
6
|
+
|
7
|
+
'use strict'
|
8
|
+
|
9
|
+
/**
|
10
|
+
* RegExp to match *( ";" parameter ) in RFC 7231 sec 3.1.1.1
|
11
|
+
*
|
12
|
+
* parameter = token "=" ( token / quoted-string )
|
13
|
+
* token = 1*tchar
|
14
|
+
* tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*"
|
15
|
+
* / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
|
16
|
+
* / DIGIT / ALPHA
|
17
|
+
* ; any VCHAR, except delimiters
|
18
|
+
* quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE
|
19
|
+
* qdtext = HTAB / SP / %x21 / %x23-5B / %x5D-7E / obs-text
|
20
|
+
* obs-text = %x80-FF
|
21
|
+
* quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text )
|
22
|
+
*/
|
23
|
+
var PARAM_REGEXP = /; *([!#$%&'*+.^_`|~0-9A-Za-z-]+) *= *("(?:[\u000b\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u000b\u0020-\u00ff])*"|[!#$%&'*+.^_`|~0-9A-Za-z-]+) */g
|
24
|
+
var TEXT_REGEXP = /^[\u000b\u0020-\u007e\u0080-\u00ff]+$/
|
25
|
+
var TOKEN_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/
|
26
|
+
|
27
|
+
/**
|
28
|
+
* RegExp to match quoted-pair in RFC 7230 sec 3.2.6
|
29
|
+
*
|
30
|
+
* quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text )
|
31
|
+
* obs-text = %x80-FF
|
32
|
+
*/
|
33
|
+
var QESC_REGEXP = /\\([\u000b\u0020-\u00ff])/g
|
34
|
+
|
35
|
+
/**
|
36
|
+
* RegExp to match chars that must be quoted-pair in RFC 7230 sec 3.2.6
|
37
|
+
*/
|
38
|
+
var QUOTE_REGEXP = /([\\"])/g
|
39
|
+
|
40
|
+
/**
|
41
|
+
* RegExp to match type in RFC 7231 sec 3.1.1.1
|
42
|
+
*
|
43
|
+
* media-type = type "/" subtype
|
44
|
+
* type = token
|
45
|
+
* subtype = token
|
46
|
+
*/
|
47
|
+
var TYPE_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Module exports.
|
51
|
+
* @public
|
52
|
+
*/
|
53
|
+
|
54
|
+
exports.format = format
|
55
|
+
exports.parse = parse
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Format object to media type.
|
59
|
+
*
|
60
|
+
* @param {object} obj
|
61
|
+
* @return {string}
|
62
|
+
* @public
|
63
|
+
*/
|
64
|
+
|
65
|
+
function format (obj) {
|
66
|
+
if (!obj || typeof obj !== 'object') {
|
67
|
+
throw new TypeError('argument obj is required')
|
68
|
+
}
|
69
|
+
|
70
|
+
var parameters = obj.parameters
|
71
|
+
var type = obj.type
|
72
|
+
|
73
|
+
if (!type || !TYPE_REGEXP.test(type)) {
|
74
|
+
throw new TypeError('invalid type')
|
75
|
+
}
|
76
|
+
|
77
|
+
var string = type
|
78
|
+
|
79
|
+
// append parameters
|
80
|
+
if (parameters && typeof parameters === 'object') {
|
81
|
+
var param
|
82
|
+
var params = Object.keys(parameters).sort()
|
83
|
+
|
84
|
+
for (var i = 0; i < params.length; i++) {
|
85
|
+
param = params[i]
|
86
|
+
|
87
|
+
if (!TOKEN_REGEXP.test(param)) {
|
88
|
+
throw new TypeError('invalid parameter name')
|
89
|
+
}
|
90
|
+
|
91
|
+
string += '; ' + param + '=' + qstring(parameters[param])
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
return string
|
96
|
+
}
|
97
|
+
|
98
|
+
/**
|
99
|
+
* Parse media type to object.
|
100
|
+
*
|
101
|
+
* @param {string|object} string
|
102
|
+
* @return {Object}
|
103
|
+
* @public
|
104
|
+
*/
|
105
|
+
|
106
|
+
function parse (string) {
|
107
|
+
if (!string) {
|
108
|
+
throw new TypeError('argument string is required')
|
109
|
+
}
|
110
|
+
|
111
|
+
// support req/res-like objects as argument
|
112
|
+
var header = typeof string === 'object'
|
113
|
+
? getcontenttype(string)
|
114
|
+
: string
|
115
|
+
|
116
|
+
if (typeof header !== 'string') {
|
117
|
+
throw new TypeError('argument string is required to be a string')
|
118
|
+
}
|
119
|
+
|
120
|
+
var index = header.indexOf(';')
|
121
|
+
var type = index !== -1
|
122
|
+
? header.substr(0, index).trim()
|
123
|
+
: header.trim()
|
124
|
+
|
125
|
+
if (!TYPE_REGEXP.test(type)) {
|
126
|
+
throw new TypeError('invalid media type')
|
127
|
+
}
|
128
|
+
|
129
|
+
var obj = new ContentType(type.toLowerCase())
|
130
|
+
|
131
|
+
// parse parameters
|
132
|
+
if (index !== -1) {
|
133
|
+
var key
|
134
|
+
var match
|
135
|
+
var value
|
136
|
+
|
137
|
+
PARAM_REGEXP.lastIndex = index
|
138
|
+
|
139
|
+
while ((match = PARAM_REGEXP.exec(header))) {
|
140
|
+
if (match.index !== index) {
|
141
|
+
throw new TypeError('invalid parameter format')
|
142
|
+
}
|
143
|
+
|
144
|
+
index += match[0].length
|
145
|
+
key = match[1].toLowerCase()
|
146
|
+
value = match[2]
|
147
|
+
|
148
|
+
if (value[0] === '"') {
|
149
|
+
// remove quotes and escapes
|
150
|
+
value = value
|
151
|
+
.substr(1, value.length - 2)
|
152
|
+
.replace(QESC_REGEXP, '$1')
|
153
|
+
}
|
154
|
+
|
155
|
+
obj.parameters[key] = value
|
156
|
+
}
|
157
|
+
|
158
|
+
if (index !== header.length) {
|
159
|
+
throw new TypeError('invalid parameter format')
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
163
|
+
return obj
|
164
|
+
}
|
165
|
+
|
166
|
+
/**
|
167
|
+
* Get content-type from req/res objects.
|
168
|
+
*
|
169
|
+
* @param {object}
|
170
|
+
* @return {Object}
|
171
|
+
* @private
|
172
|
+
*/
|
173
|
+
|
174
|
+
function getcontenttype (obj) {
|
175
|
+
var header
|
176
|
+
|
177
|
+
if (typeof obj.getHeader === 'function') {
|
178
|
+
// res-like
|
179
|
+
header = obj.getHeader('content-type')
|
180
|
+
} else if (typeof obj.headers === 'object') {
|
181
|
+
// req-like
|
182
|
+
header = obj.headers && obj.headers['content-type']
|
183
|
+
}
|
184
|
+
|
185
|
+
if (typeof header !== 'string') {
|
186
|
+
throw new TypeError('content-type header is missing from object')
|
187
|
+
}
|
188
|
+
|
189
|
+
return header
|
190
|
+
}
|
191
|
+
|
192
|
+
/**
|
193
|
+
* Quote a string if necessary.
|
194
|
+
*
|
195
|
+
* @param {string} val
|
196
|
+
* @return {string}
|
197
|
+
* @private
|
198
|
+
*/
|
199
|
+
|
200
|
+
function qstring (val) {
|
201
|
+
var str = String(val)
|
202
|
+
|
203
|
+
// no need to quote tokens
|
204
|
+
if (TOKEN_REGEXP.test(str)) {
|
205
|
+
return str
|
206
|
+
}
|
207
|
+
|
208
|
+
if (str.length > 0 && !TEXT_REGEXP.test(str)) {
|
209
|
+
throw new TypeError('invalid parameter value')
|
210
|
+
}
|
211
|
+
|
212
|
+
return '"' + str.replace(QUOTE_REGEXP, '\\$1') + '"'
|
213
|
+
}
|
214
|
+
|
215
|
+
/**
|
216
|
+
* Class to represent a content type.
|
217
|
+
* @private
|
218
|
+
*/
|
219
|
+
function ContentType (type) {
|
220
|
+
this.parameters = Object.create(null)
|
221
|
+
this.type = type
|
222
|
+
}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
{
|
2
|
+
"name": "content-type",
|
3
|
+
"description": "Create and parse HTTP Content-Type header",
|
4
|
+
"version": "1.0.4",
|
5
|
+
"author": "Douglas Christopher Wilson <doug@somethingdoug.com>",
|
6
|
+
"license": "MIT",
|
7
|
+
"keywords": [
|
8
|
+
"content-type",
|
9
|
+
"http",
|
10
|
+
"req",
|
11
|
+
"res",
|
12
|
+
"rfc7231"
|
13
|
+
],
|
14
|
+
"repository": "jshttp/content-type",
|
15
|
+
"devDependencies": {
|
16
|
+
"eslint": "3.19.0",
|
17
|
+
"eslint-config-standard": "10.2.1",
|
18
|
+
"eslint-plugin-import": "2.7.0",
|
19
|
+
"eslint-plugin-node": "5.1.1",
|
20
|
+
"eslint-plugin-promise": "3.5.0",
|
21
|
+
"eslint-plugin-standard": "3.0.1",
|
22
|
+
"istanbul": "0.4.5",
|
23
|
+
"mocha": "~1.21.5"
|
24
|
+
},
|
25
|
+
"files": [
|
26
|
+
"LICENSE",
|
27
|
+
"HISTORY.md",
|
28
|
+
"README.md",
|
29
|
+
"index.js"
|
30
|
+
],
|
31
|
+
"engines": {
|
32
|
+
"node": ">= 0.6"
|
33
|
+
},
|
34
|
+
"scripts": {
|
35
|
+
"lint": "eslint .",
|
36
|
+
"test": "mocha --reporter spec --check-leaks --bail test/",
|
37
|
+
"test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/",
|
38
|
+
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/"
|
39
|
+
}
|
40
|
+
}
|
@@ -0,0 +1,128 @@
|
|
1
|
+
0.4.1 / 2020-04-21
|
2
|
+
==================
|
3
|
+
|
4
|
+
* Fix `maxAge` option to reject invalid values
|
5
|
+
|
6
|
+
0.4.0 / 2019-05-15
|
7
|
+
==================
|
8
|
+
|
9
|
+
* Add `SameSite=None` support
|
10
|
+
|
11
|
+
0.3.1 / 2016-05-26
|
12
|
+
==================
|
13
|
+
|
14
|
+
* Fix `sameSite: true` to work with draft-7 clients
|
15
|
+
- `true` now sends `SameSite=Strict` instead of `SameSite`
|
16
|
+
|
17
|
+
0.3.0 / 2016-05-26
|
18
|
+
==================
|
19
|
+
|
20
|
+
* Add `sameSite` option
|
21
|
+
- Replaces `firstPartyOnly` option, never implemented by browsers
|
22
|
+
* Improve error message when `encode` is not a function
|
23
|
+
* Improve error message when `expires` is not a `Date`
|
24
|
+
|
25
|
+
0.2.4 / 2016-05-20
|
26
|
+
==================
|
27
|
+
|
28
|
+
* perf: enable strict mode
|
29
|
+
* perf: use for loop in parse
|
30
|
+
* perf: use string concatination for serialization
|
31
|
+
|
32
|
+
0.2.3 / 2015-10-25
|
33
|
+
==================
|
34
|
+
|
35
|
+
* Fix cookie `Max-Age` to never be a floating point number
|
36
|
+
|
37
|
+
0.2.2 / 2015-09-17
|
38
|
+
==================
|
39
|
+
|
40
|
+
* Fix regression when setting empty cookie value
|
41
|
+
- Ease the new restriction, which is just basic header-level validation
|
42
|
+
* Fix typo in invalid value errors
|
43
|
+
|
44
|
+
0.2.1 / 2015-09-17
|
45
|
+
==================
|
46
|
+
|
47
|
+
* Throw on invalid values provided to `serialize`
|
48
|
+
- Ensures the resulting string is a valid HTTP header value
|
49
|
+
|
50
|
+
0.2.0 / 2015-08-13
|
51
|
+
==================
|
52
|
+
|
53
|
+
* Add `firstPartyOnly` option
|
54
|
+
* Throw better error for invalid argument to parse
|
55
|
+
* perf: hoist regular expression
|
56
|
+
|
57
|
+
0.1.5 / 2015-09-17
|
58
|
+
==================
|
59
|
+
|
60
|
+
* Fix regression when setting empty cookie value
|
61
|
+
- Ease the new restriction, which is just basic header-level validation
|
62
|
+
* Fix typo in invalid value errors
|
63
|
+
|
64
|
+
0.1.4 / 2015-09-17
|
65
|
+
==================
|
66
|
+
|
67
|
+
* Throw better error for invalid argument to parse
|
68
|
+
* Throw on invalid values provided to `serialize`
|
69
|
+
- Ensures the resulting string is a valid HTTP header value
|
70
|
+
|
71
|
+
0.1.3 / 2015-05-19
|
72
|
+
==================
|
73
|
+
|
74
|
+
* Reduce the scope of try-catch deopt
|
75
|
+
* Remove argument reassignments
|
76
|
+
|
77
|
+
0.1.2 / 2014-04-16
|
78
|
+
==================
|
79
|
+
|
80
|
+
* Remove unnecessary files from npm package
|
81
|
+
|
82
|
+
0.1.1 / 2014-02-23
|
83
|
+
==================
|
84
|
+
|
85
|
+
* Fix bad parse when cookie value contained a comma
|
86
|
+
* Fix support for `maxAge` of `0`
|
87
|
+
|
88
|
+
0.1.0 / 2013-05-01
|
89
|
+
==================
|
90
|
+
|
91
|
+
* Add `decode` option
|
92
|
+
* Add `encode` option
|
93
|
+
|
94
|
+
0.0.6 / 2013-04-08
|
95
|
+
==================
|
96
|
+
|
97
|
+
* Ignore cookie parts missing `=`
|
98
|
+
|
99
|
+
0.0.5 / 2012-10-29
|
100
|
+
==================
|
101
|
+
|
102
|
+
* Return raw cookie value if value unescape errors
|
103
|
+
|
104
|
+
0.0.4 / 2012-06-21
|
105
|
+
==================
|
106
|
+
|
107
|
+
* Use encode/decodeURIComponent for cookie encoding/decoding
|
108
|
+
- Improve server/client interoperability
|
109
|
+
|
110
|
+
0.0.3 / 2012-06-06
|
111
|
+
==================
|
112
|
+
|
113
|
+
* Only escape special characters per the cookie RFC
|
114
|
+
|
115
|
+
0.0.2 / 2012-06-01
|
116
|
+
==================
|
117
|
+
|
118
|
+
* Fix `maxAge` option to not throw error
|
119
|
+
|
120
|
+
0.0.1 / 2012-05-28
|
121
|
+
==================
|
122
|
+
|
123
|
+
* Add more tests
|
124
|
+
|
125
|
+
0.0.0 / 2012-05-28
|
126
|
+
==================
|
127
|
+
|
128
|
+
* Initial release
|
@@ -0,0 +1,24 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2012-2014 Roman Shtylman <shtylman@gmail.com>
|
4
|
+
Copyright (c) 2015 Douglas Christopher Wilson <doug@somethingdoug.com>
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
'Software'), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
20
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
21
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
22
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
23
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
|
@@ -0,0 +1,257 @@
|
|
1
|
+
# cookie
|
2
|
+
|
3
|
+
[![NPM Version][npm-version-image]][npm-url]
|
4
|
+
[![NPM Downloads][npm-downloads-image]][npm-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
|
+
Basic HTTP cookie parser and serializer for HTTP servers.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
This is a [Node.js](https://nodejs.org/en/) module available through the
|
14
|
+
[npm registry](https://www.npmjs.com/). Installation is done using the
|
15
|
+
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
|
16
|
+
|
17
|
+
```sh
|
18
|
+
$ npm install cookie
|
19
|
+
```
|
20
|
+
|
21
|
+
## API
|
22
|
+
|
23
|
+
```js
|
24
|
+
var cookie = require('cookie');
|
25
|
+
```
|
26
|
+
|
27
|
+
### cookie.parse(str, options)
|
28
|
+
|
29
|
+
Parse an HTTP `Cookie` header string and returning an object of all cookie name-value pairs.
|
30
|
+
The `str` argument is the string representing a `Cookie` header value and `options` is an
|
31
|
+
optional object containing additional parsing options.
|
32
|
+
|
33
|
+
```js
|
34
|
+
var cookies = cookie.parse('foo=bar; equation=E%3Dmc%5E2');
|
35
|
+
// { foo: 'bar', equation: 'E=mc^2' }
|
36
|
+
```
|
37
|
+
|
38
|
+
#### Options
|
39
|
+
|
40
|
+
`cookie.parse` accepts these properties in the options object.
|
41
|
+
|
42
|
+
##### decode
|
43
|
+
|
44
|
+
Specifies a function that will be used to decode a cookie's value. Since the value of a cookie
|
45
|
+
has a limited character set (and must be a simple string), this function can be used to decode
|
46
|
+
a previously-encoded cookie value into a JavaScript string or other object.
|
47
|
+
|
48
|
+
The default function is the global `decodeURIComponent`, which will decode any URL-encoded
|
49
|
+
sequences into their byte representations.
|
50
|
+
|
51
|
+
**note** if an error is thrown from this function, the original, non-decoded cookie value will
|
52
|
+
be returned as the cookie's value.
|
53
|
+
|
54
|
+
### cookie.serialize(name, value, options)
|
55
|
+
|
56
|
+
Serialize a cookie name-value pair into a `Set-Cookie` header string. The `name` argument is the
|
57
|
+
name for the cookie, the `value` argument is the value to set the cookie to, and the `options`
|
58
|
+
argument is an optional object containing additional serialization options.
|
59
|
+
|
60
|
+
```js
|
61
|
+
var setCookie = cookie.serialize('foo', 'bar');
|
62
|
+
// foo=bar
|
63
|
+
```
|
64
|
+
|
65
|
+
#### Options
|
66
|
+
|
67
|
+
`cookie.serialize` accepts these properties in the options object.
|
68
|
+
|
69
|
+
##### domain
|
70
|
+
|
71
|
+
Specifies the value for the [`Domain` `Set-Cookie` attribute][rfc-6265-5.2.3]. By default, no
|
72
|
+
domain is set, and most clients will consider the cookie to apply to only the current domain.
|
73
|
+
|
74
|
+
##### encode
|
75
|
+
|
76
|
+
Specifies a function that will be used to encode a cookie's value. Since value of a cookie
|
77
|
+
has a limited character set (and must be a simple string), this function can be used to encode
|
78
|
+
a value into a string suited for a cookie's value.
|
79
|
+
|
80
|
+
The default function is the global `encodeURIComponent`, which will encode a JavaScript string
|
81
|
+
into UTF-8 byte sequences and then URL-encode any that fall outside of the cookie range.
|
82
|
+
|
83
|
+
##### expires
|
84
|
+
|
85
|
+
Specifies the `Date` object to be the value for the [`Expires` `Set-Cookie` attribute][rfc-6265-5.2.1].
|
86
|
+
By default, no expiration is set, and most clients will consider this a "non-persistent cookie" and
|
87
|
+
will delete it on a condition like exiting a web browser application.
|
88
|
+
|
89
|
+
**note** the [cookie storage model specification][rfc-6265-5.3] states that if both `expires` and
|
90
|
+
`maxAge` are set, then `maxAge` takes precedence, but it is possible not all clients by obey this,
|
91
|
+
so if both are set, they should point to the same date and time.
|
92
|
+
|
93
|
+
##### httpOnly
|
94
|
+
|
95
|
+
Specifies the `boolean` value for the [`HttpOnly` `Set-Cookie` attribute][rfc-6265-5.2.6]. When truthy,
|
96
|
+
the `HttpOnly` attribute is set, otherwise it is not. By default, the `HttpOnly` attribute is not set.
|
97
|
+
|
98
|
+
**note** be careful when setting this to `true`, as compliant clients will not allow client-side
|
99
|
+
JavaScript to see the cookie in `document.cookie`.
|
100
|
+
|
101
|
+
##### maxAge
|
102
|
+
|
103
|
+
Specifies the `number` (in seconds) to be the value for the [`Max-Age` `Set-Cookie` attribute][rfc-6265-5.2.2].
|
104
|
+
The given number will be converted to an integer by rounding down. By default, no maximum age is set.
|
105
|
+
|
106
|
+
**note** the [cookie storage model specification][rfc-6265-5.3] states that if both `expires` and
|
107
|
+
`maxAge` are set, then `maxAge` takes precedence, but it is possible not all clients by obey this,
|
108
|
+
so if both are set, they should point to the same date and time.
|
109
|
+
|
110
|
+
##### path
|
111
|
+
|
112
|
+
Specifies the value for the [`Path` `Set-Cookie` attribute][rfc-6265-5.2.4]. By default, the path
|
113
|
+
is considered the ["default path"][rfc-6265-5.1.4].
|
114
|
+
|
115
|
+
##### sameSite
|
116
|
+
|
117
|
+
Specifies the `boolean` or `string` to be the value for the [`SameSite` `Set-Cookie` attribute][rfc-6265bis-03-4.1.2.7].
|
118
|
+
|
119
|
+
- `true` will set the `SameSite` attribute to `Strict` for strict same site enforcement.
|
120
|
+
- `false` will not set the `SameSite` attribute.
|
121
|
+
- `'lax'` will set the `SameSite` attribute to `Lax` for lax same site enforcement.
|
122
|
+
- `'none'` will set the `SameSite` attribute to `None` for an explicit cross-site cookie.
|
123
|
+
- `'strict'` will set the `SameSite` attribute to `Strict` for strict same site enforcement.
|
124
|
+
|
125
|
+
More information about the different enforcement levels can be found in
|
126
|
+
[the specification][rfc-6265bis-03-4.1.2.7].
|
127
|
+
|
128
|
+
**note** This is an attribute that has not yet been fully standardized, and may change in the future.
|
129
|
+
This also means many clients may ignore this attribute until they understand it.
|
130
|
+
|
131
|
+
##### secure
|
132
|
+
|
133
|
+
Specifies the `boolean` value for the [`Secure` `Set-Cookie` attribute][rfc-6265-5.2.5]. When truthy,
|
134
|
+
the `Secure` attribute is set, otherwise it is not. By default, the `Secure` attribute is not set.
|
135
|
+
|
136
|
+
**note** be careful when setting this to `true`, as compliant clients will not send the cookie back to
|
137
|
+
the server in the future if the browser does not have an HTTPS connection.
|
138
|
+
|
139
|
+
## Example
|
140
|
+
|
141
|
+
The following example uses this module in conjunction with the Node.js core HTTP server
|
142
|
+
to prompt a user for their name and display it back on future visits.
|
143
|
+
|
144
|
+
```js
|
145
|
+
var cookie = require('cookie');
|
146
|
+
var escapeHtml = require('escape-html');
|
147
|
+
var http = require('http');
|
148
|
+
var url = require('url');
|
149
|
+
|
150
|
+
function onRequest(req, res) {
|
151
|
+
// Parse the query string
|
152
|
+
var query = url.parse(req.url, true, true).query;
|
153
|
+
|
154
|
+
if (query && query.name) {
|
155
|
+
// Set a new cookie with the name
|
156
|
+
res.setHeader('Set-Cookie', cookie.serialize('name', String(query.name), {
|
157
|
+
httpOnly: true,
|
158
|
+
maxAge: 60 * 60 * 24 * 7 // 1 week
|
159
|
+
}));
|
160
|
+
|
161
|
+
// Redirect back after setting cookie
|
162
|
+
res.statusCode = 302;
|
163
|
+
res.setHeader('Location', req.headers.referer || '/');
|
164
|
+
res.end();
|
165
|
+
return;
|
166
|
+
}
|
167
|
+
|
168
|
+
// Parse the cookies on the request
|
169
|
+
var cookies = cookie.parse(req.headers.cookie || '');
|
170
|
+
|
171
|
+
// Get the visitor name set in the cookie
|
172
|
+
var name = cookies.name;
|
173
|
+
|
174
|
+
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
|
175
|
+
|
176
|
+
if (name) {
|
177
|
+
res.write('<p>Welcome back, <b>' + escapeHtml(name) + '</b>!</p>');
|
178
|
+
} else {
|
179
|
+
res.write('<p>Hello, new visitor!</p>');
|
180
|
+
}
|
181
|
+
|
182
|
+
res.write('<form method="GET">');
|
183
|
+
res.write('<input placeholder="enter your name" name="name"> <input type="submit" value="Set Name">');
|
184
|
+
res.end('</form>');
|
185
|
+
}
|
186
|
+
|
187
|
+
http.createServer(onRequest).listen(3000);
|
188
|
+
```
|
189
|
+
|
190
|
+
## Testing
|
191
|
+
|
192
|
+
```sh
|
193
|
+
$ npm test
|
194
|
+
```
|
195
|
+
|
196
|
+
## Benchmark
|
197
|
+
|
198
|
+
```
|
199
|
+
$ npm run bench
|
200
|
+
|
201
|
+
> cookie@0.3.1 bench cookie
|
202
|
+
> node benchmark/index.js
|
203
|
+
|
204
|
+
http_parser@2.8.0
|
205
|
+
node@6.14.2
|
206
|
+
v8@5.1.281.111
|
207
|
+
uv@1.16.1
|
208
|
+
zlib@1.2.11
|
209
|
+
ares@1.10.1-DEV
|
210
|
+
icu@58.2
|
211
|
+
modules@48
|
212
|
+
napi@3
|
213
|
+
openssl@1.0.2o
|
214
|
+
|
215
|
+
> node benchmark/parse.js
|
216
|
+
|
217
|
+
cookie.parse
|
218
|
+
|
219
|
+
6 tests completed.
|
220
|
+
|
221
|
+
simple x 1,200,691 ops/sec ±1.12% (189 runs sampled)
|
222
|
+
decode x 1,012,994 ops/sec ±0.97% (186 runs sampled)
|
223
|
+
unquote x 1,074,174 ops/sec ±2.43% (186 runs sampled)
|
224
|
+
duplicates x 438,424 ops/sec ±2.17% (184 runs sampled)
|
225
|
+
10 cookies x 147,154 ops/sec ±1.01% (186 runs sampled)
|
226
|
+
100 cookies x 14,274 ops/sec ±1.07% (187 runs sampled)
|
227
|
+
```
|
228
|
+
|
229
|
+
## References
|
230
|
+
|
231
|
+
- [RFC 6265: HTTP State Management Mechanism][rfc-6265]
|
232
|
+
- [Same-site Cookies][rfc-6265bis-03-4.1.2.7]
|
233
|
+
|
234
|
+
[rfc-6265bis-03-4.1.2.7]: https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7
|
235
|
+
[rfc-6265]: https://tools.ietf.org/html/rfc6265
|
236
|
+
[rfc-6265-5.1.4]: https://tools.ietf.org/html/rfc6265#section-5.1.4
|
237
|
+
[rfc-6265-5.2.1]: https://tools.ietf.org/html/rfc6265#section-5.2.1
|
238
|
+
[rfc-6265-5.2.2]: https://tools.ietf.org/html/rfc6265#section-5.2.2
|
239
|
+
[rfc-6265-5.2.3]: https://tools.ietf.org/html/rfc6265#section-5.2.3
|
240
|
+
[rfc-6265-5.2.4]: https://tools.ietf.org/html/rfc6265#section-5.2.4
|
241
|
+
[rfc-6265-5.2.5]: https://tools.ietf.org/html/rfc6265#section-5.2.5
|
242
|
+
[rfc-6265-5.2.6]: https://tools.ietf.org/html/rfc6265#section-5.2.6
|
243
|
+
[rfc-6265-5.3]: https://tools.ietf.org/html/rfc6265#section-5.3
|
244
|
+
|
245
|
+
## License
|
246
|
+
|
247
|
+
[MIT](LICENSE)
|
248
|
+
|
249
|
+
[coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/cookie/master
|
250
|
+
[coveralls-url]: https://coveralls.io/r/jshttp/cookie?branch=master
|
251
|
+
[node-version-image]: https://badgen.net/npm/node/cookie
|
252
|
+
[node-version-url]: https://nodejs.org/en/download
|
253
|
+
[npm-downloads-image]: https://badgen.net/npm/dm/cookie
|
254
|
+
[npm-url]: https://npmjs.org/package/cookie
|
255
|
+
[npm-version-image]: https://badgen.net/npm/v/cookie
|
256
|
+
[travis-image]: https://badgen.net/travis/jshttp/cookie/master
|
257
|
+
[travis-url]: https://travis-ci.org/jshttp/cookie
|