Cookie的名称是否区分大小写? [英] Is the name of a cookie case sensitive?

查看:1722
本文介绍了Cookie的名称是否区分大小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTTP Cookie由名称/值对组成,可由服务器使用此响应设置:

A HTTP Cookie consists of a name-value pair and can be set by the server using this response:

HTTP/1.0 200 OK
Content-type: text/html
Set-Cookie: name=value
Set-Cookie: name2=value2; Expires=Wed, 09 Jun 2021 10:18:14 GMT

来自客户端的未来请求像这样:

Future requests from the client will then look like this:

GET /spec.html HTTP/1.1
Host: www.example.org
Cookie: name=value; name2=value2

Cookie的名称是否区分大小写?

Is the name of the cookie case sensitive?

例如,如果我的服务器发送响应,如下所示:

For example, if my server sends a response as such:

HTTP/1.0 200 OK
Content-type: text/html
Set-Cookie: Aaaa=Bbbb
Set-Cookie: aAaa=bBbb
Set-Cookie: aaAa=bbBb
Set-Cookie: aaaA=bbbB

是否合理期待客户端(Chrome,FireFox,Safari,IExplorer,Opera等)使用头 Cookie发送未来请求:Aaaa = Bbbb; aAaa = bBbb; aaAa = bbBb; aaaA = bbbB;

Is it reasonable to expect a client (Chrome, FireFox, Safari, IExplorer, Opera, etc) to send future requests with the header Cookie: Aaaa=Bbbb; aAaa=bBbb; aaAa=bbBb; aaaA=bbbB;?

注意:问题既不是JSP特定的, sub>

Note: Question is neither JSP-specific, PHP-specific, nor ASP-specific.

推荐答案

Cookie名称是区分大小写的敏感。 RFC没有明确说明,但是每个case - 不敏感的比较是如此明确地说明的,并且没有关于cookie名称的这种明确的陈述。

Cookie names are case-sensitive. The RFC does not state that explicitly, but each case-insensitive comparison is stated so explicitly, and there is no such explicit statement regarding the name of the cookie. Chrome and Firefox both treat cookies as case-sensitive and preserve all case variants as distinct cookies.

测试用例(PHP):

print_r($_COOKIE);

setcookie('foo', '123');
setcookie('Foo', '456');

加载脚本两次,观察 $ _ COOKIE 第二次运行。

Load script twice, observe $_COOKIE dump on second run.

这篇关于Cookie的名称是否区分大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆