浏览器未考虑HTTP Set-cookie标头

时间:2014-02-10 21:44:13

标签: django http cookies http-headers

我有一个提供文件的网络服务器。这是我提出的要求和答案:

GET / HTTP/1.1
Host: 127.0.0.1:8004
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131030 Firefox/17.0 Iceweasel/17.0.10
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: djdt=hide; sessionid=1ksbrjhfunsjtywlk2q4p2rl7zrsyvza; messages="Nice and all"
Cache-Control: max-age=0


HTTP/1.0 200 OK
Set-Cookie: csrftoken=Xkg4CnLEahplJPHEJGLrmGvPjebMqyh9; expires=Mon, 09-Feb-2015 21:15:51 GMT; Max-Age=31449600; Path=/, sessionid=qy5guifmpkra78ubkztxxlmk3tu5vr7s; expires=Mon, 24-Feb-2014 21:15:51 GMT; httponly; Max-Age=1209600; Path=/, messages=; expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/
Vary: Cookie
Server: gunicorn/18.0
Date: Mon, 10 Feb 2014 21:15:51 GMT
x-frame-options: SAMEORIGIN
Content-Type: text/html; charset=utf-8

到目前为止一切都很好。在下一个请求中,事情变得奇怪:

GET /static/css/bootstrap.css HTTP/1.1
Host: 127.0.0.1:8004
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131030 Firefox/17.0 Iceweasel/17.0.10
Accept: text/css,*/*;q=0.1
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://127.0.0.1:8004/
Cookie: djdt=hide; sessionid=1ksbrjhfunsjtywlk2q4p2rl7zrsyvza; messages="Nice and all"
If-Modified-Since: Sun, 13 Oct 2013 20:23:36 GMT
Cache-Control: max-age=0


HTTP/1.0 304 NOT MODIFIED
Date: Mon, 10 Feb 2014 21:15:54 GMT
Server: WSGIServer/0.1 Python/2.7.3
Content-Length: 0

是的,浏览器(Iceweasel)刚刚发送了以前的cookie,而不是发送新的cookie。实际上,它不会考虑set-cookie HTTP标头。我不明白。 Chromium上的行为相同。在两个浏览器上,控制台中都没有任何内容。当使用来自Iceweasel的开发人员工具来查看请求时,先前的cookie将在“已发送的cookie”中进行解析,但收到的cookie不会被解析,例如它在此(否则无关)捕获中: Example of received cookie being parsed

在提供静态文件时,您可能已经注意到Server HTTP响应标头不同。实际上,本地Django应用程序在请求页面时充当代理,但自己提供静态内容。这两个内容都位于同一个域,相同的端口上,因此从浏览器的角度来看,这应该是相同的。

0 个答案:

没有答案