gpt4 book ai didi

cookies - 在 cookie 路径上设置斜杠?

转载 作者:行者123 更新时间:2023-12-02 12:30:07 35 4
gpt4 key购买 nike

是否存在是否在 cookie 路径末尾设置斜杠的最佳实践?是路径路径/以任何方式?我发现两个版本都会产生不同的 cookie,但我不知道首选哪个版本。

最佳答案

就服务器端而言,此问题 ( https://bugzilla.mozilla.org/show_bug.cgi?id=469678 ) 指出:

Per RFC 2109 the default path of a cookie when set by Set-Cookie is:

Defaults to the path of the request URL that generated the Set-Cookie response, up to, but not including, the right-most /.

因此,这是不应使用尾部斜杠的一种视角。

<小时/>

RFC 历史

RFC 2109,1997 年 2 月,HTTP 状态管理机制

https://www.rfc-editor.org/rfc/rfc2109

  • 请参阅4.3.1 解释 Set-Cookie
  • 默认为生成 Set-Cookie 响应的请求 URL 的路径,直到但不包括最右边的/。

不要包含尾随“/”。

RFC 2965,2000 年 10 月,HTTP 状态管理机制

已过时:2109

https://www.rfc-editor.org/rfc/rfc2965

  • 请参阅3.3.1 解释 Set-Cookie2
  • 默认为生成 Set-Cookie2 响应的请求 URL 的路径,直至并包括最右侧的/。

务必包含尾随“/”。

RFC 6265,2011 年 4 月,HTTP 状态管理机制

已过时:2965

https://www.rfc-editor.org/rfc/rfc6265#section-5.2.4

  • 参见5.1.4。路径和路径匹配
  • -3。如果uri-path包含不超过1个%x2F(“/”)字符,则输出%x2F(“/”)并跳过剩余步骤。
  • -4。输出 uri-path 中从第一个字符到(但不包括)最右边的 %x2F(“/”)的字符。

不要包含尾随“/”。

<小时/>

客户端测试

在客户端,如果使用以下代码:

document.cookie="a=1"

您可以通过检查每个浏览器的开发工具来获得这些结果(我的网站有一个 window.location.pathname="/selenium/tests/testCustomizeColumnsPage.html")

Chrome/71.0.3578   /selenium/tests
Firefox/64.0 /selenium/tests/
Edge /selenium/tests/
IE11 devtools doesn't show cookies, think the path includes the trailing '/'

Chrome 在这里错了吗?

<小时/>

其他引用:

关于cookies - 在 cookie 路径上设置斜杠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36131023/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com