如何处理 HTTP 响应中的多个 Set-Cookie 标头

发布于 2024-08-09 08:24:23 字数 308 浏览 3 评论 0原文

我正在尝试出于某种目的编写简单的代理服务器。在其中我使用 httplib 来访问远程 Web 服务器。但有一个问题:Web 服务器在一个响应中返回两个 Set-Cookie 标头,而 httplib 在 httplib.HTTPResponse.getheaders() 中将它们混合在一起,有效地用逗号连接 cookie [这很奇怪,因为 getheaders 返回一个 LIST,而不是 DICT,所以我认为他们用多个同名的标题来编写它)。因此,当我将这个连接的标头发送回客户端时,它会让客户端感到困惑。如何获取 httplib 中标头的完整列表(而不只是用逗号分割 Set-Cookie 标头)?

I'm trying to write simple proxy server for some purpose. In it I use httplib to access remote web-server. But there's one problem: web server returns TWO Set-Cookie headers in one response, and httplib mangles them together in httplib.HTTPResponse.getheaders(), effectively joining cookies with comma [which is strange, because getheaders returns a LIST, not DICT, so I thought they wrote it with multiple headers of the same name). So, when I send this joined header back to client, it confuses client. How can I obtain full list of headers in httplib (without just splitting Set-Cookie header on commas)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿港巷口少年归 2024-08-16 08:24:23

HTTPResponse.getheaders() 返回组合标头的列表(实际上是我的调用 dict.items())。唯一不受影响地存储传入标头的位置是 HTTPResponse.msg.headers。

HTTPResponse.getheaders() returns a list of combined headers (actually my calling dict.items()). The only place where incoming headers are stored untouched is HTTPResponse.msg.headers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文