Set-Cookie 是否包含多个 cookie?
我正在 Node.JS 中进行一些类似于浏览器的 cookie 处理,并想知道从 NodeJS 和 HTTP 客户端 - 是否支持 cookies?
代码会删除第一个分号之后的所有内容。
var cookie = get(response.headers, "Set-Cookie")
if (cookie) {
cookie = (cookie + "").split(";").shift()
set(opts.headers, "Cookie", cookie)
}
我将以有限的方式对此进行扩展,并研究如何避免未来步骤的重写。
我见过使用多个 Set-Cookie 标头设置多个 cookie。
I am working on some browser-like cookie handling in Node.JS and want to know how far to expand on this code from NodeJS and HTTP Client - Are cookies supported?
The code drops everything after the first semicolon.
var cookie = get(response.headers, "Set-Cookie")
if (cookie) {
cookie = (cookie + "").split(";").shift()
set(opts.headers, "Cookie", cookie)
}
I will expand on that in limited ways and am looking at how to avoid a re-write for future steps.
I have seen multiple cookies being set using multiple Set-Cookie headers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
删除第一个分号之后的所有内容是一个坏主意,因为它携带 cookie 元数据。这是我从 StackOverflow 收到的 Set-Cookie 标头(稍作编辑):
设置的多个 cookie 如下所示:
因此 cookie 字符串解析起来相当复杂,所以我认为没有一种简单的方法可以完成此操作......
Dropping everything after the first semicolon is a bad idea, since that carries the cookie metadata. Here's the Set-Cookie header I received from StackOverflow (slightly redacted):
Multiple cookies being set looks like this:
So the cookie string is rather complex to parse, so I don’t think there's a simple way to accomplish this…