Set-Cookie是否包含多个Cookie? [英] Does Set-Cookie ever contain more than one cookie?
问题描述
我正在处理Node.JS中的一些类似浏览器的cookie处理,并且希望知道从 NodeJS和HTTP客户端 - 支持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.
我看到多个Cookie是使用多个Set-Cookie头设置的。
I have seen multiple cookies being set using multiple Set-Cookie headers.
推荐答案
删除第一个分号后的所有内容是一个坏主意,因为它带有cookie元数据。这里是我从StackOverflow(略微修订)收到的Set-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):
usr=t=ABCDEFGHIJ&s=23412341234; domain=.stackoverflow.com; expires=Fri, 04-Nov-2011 07:39:57 GMT; path=/; HttpOnly
设置的多个Cookie看起来像这样:
Multiple cookies being set looks like this:
hest2=spam, pony2=spam, sovs2=spam; expires=Wed, 04-May-2011 07:51:27 GMT, NO_CACHE=Y; expires=Wed, 04-May-2011 07:56:27 GMT; path=/; domain=.something.d6.revealit.dk
因此cookie字符串解析起来相当复杂,我不认为有一个简单的方法来完成这个...
So the cookie string is rather complex to parse, so I don’t think there's a simple way to accomplish this…
这篇关于Set-Cookie是否包含多个Cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!