set_cookie 写出的头长什么样?中文和特殊字符怎么处理?删除 cookie 为什么删不掉?请求里的 Cookie 头怎么解析?超过大小限制会怎样?这篇逐项打印。
Set-Cookie: plain=v1; Path=/ Set-Cookie: opts=v2; Expires=Fri, 02 Oct 2026 04:28:31 GMT; Max-Age=3600; Secure; HttpOnly; Path=/app; SameSite=Lax Set-Cookie: cn="\344\270\255\346\226\207 \347\251\272\346\240\274\073\345\210\206\345\217\267\054\351\200\227\345\217\267\"\345\274\225\345\217\267"; Path=/ Set-Cookie: exp=v; Expires=Tue, 01 Jan 2030 00:00:00 GMT; Path=/
上一篇:Last-Modified 与缓存响应;下一篇:Signed Cookie;安全属性专题:HttpOnly、Secure、SameSite。
Set-Cookie: plain=; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Max-Age=0; Path=/ Set-Cookie: opts=; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Max-Age=0; Path=/app
正常 Cookie: 'a=1; b=2' → {'a': '1', 'b': '2'}
带引号的值 Cookie: 'a="x y"' → {'a': 'x y'}
重复的名字 Cookie: 'a=1; a=2' → {'a': '1'}
没有等号 Cookie: 'a=1; b; c=3' → {'a': '1', 'b': '', 'c': '3'}
值里有等号 Cookie: 'a=b=c' → {'a': 'b=c'}
空值 Cookie: 'a=; b=2' → {'a': '', 'b': '2'}
名字大小写 Cookie: 'A=1; a=2' → {'A': '1', 'a': '2'}
百分号 Cookie: 'a=%E4%B8%AD' → {'a': '%E4%B8%AD'}
原始 UTF-8 Cookie: 'a=ä¸\xad' → {'a': 'ä¸\xad'}
分号后没空格 Cookie: 'a=1;b=2' → {'a': '1', 'b': '2'}
带空格的名字 Cookie: 'my cookie=1' → {} GET /set 之后 GET /read 看到的 cookies: {'cn': '中文 空格;分号,逗号"引号', 'exp': 'v', 'plain': 'v1'} (opts 的 path=/app 与 secure,所以 /read 没带它)
jar 里的键: ['cn(path=/)', 'exp(path=/)', 'opts(path=/app)', 'plain(path=/)']中文那条 cn 在客户端看到的原始值: '"\\344\\270\\255\\346\\226\\207 \\347\\251\\272\\346\\240\\274\\073\\345\\210\\206\\345\\217\\267\\054\\351\\200\\227\\345\\217\\267\\"\\345\\274\\225\\345\\217\\267"' 再发回来后 request.cookies["cn"] = '中文 空格;分号,逗号"引号'
MAX_COOKIE_SIZE = 4093 设置 5000 字节的 cookie:状态 200 | 警告: ["The 'big' cookie is too large: the value was 5000 bytes but the header required 12 extra bytes. The final size was 5012 bytes but the limit is 4093 by"] Set-Cookie 头长度: 5012
samesite='Lax' → s=1; Path=/; SameSite=Lax samesite='Strict' → s=1; Path=/; SameSite=Strict samesite='None' → s=1; Secure; Path=/; SameSite=None samesite='bogus' → ValueError: SameSite must be 'Strict', 'Lax', or 'None'. samesite=None → s=1; Path=/ partitioned=True: p=v; Secure; Path=/; Partitioned