在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:expressjs/cookie-parser开源软件地址:https://github.com/expressjs/cookie-parser开源编程语言:JavaScript 100.0%开源软件介绍:cookie-parserParse Installation$ npm install cookie-parser APIvar cookieParser = require('cookie-parser') cookieParser(secret, options)Create a new cookie parser middleware function using the given
The middleware will parse the When In addition, this module supports special "JSON cookies". These are cookie where
the value is prefixed with cookieParser.JSONCookie(str)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. cookieParser.JSONCookies(cookies)Given an object, this will iterate over the keys and call cookieParser.signedCookie(str, secret)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, The cookieParser.signedCookies(cookies, secret)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. The Examplevar express = require('express')
var cookieParser = require('cookie-parser')
var app = express()
app.use(cookieParser())
app.get('/', function (req, res) {
// Cookies that have not been signed
console.log('Cookies: ', req.cookies)
// Cookies that have been signed
console.log('Signed Cookies: ', req.signedCookies)
})
app.listen(8080)
// curl command that sends an HTTP request with two cookies
// curl http://127.0.0.1:8080 --cookie "Cho=Kim;Greet=Hello" License |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论