如何在HTTP响应中处理多个Set

编程入门 行业动态 更新时间:2024-10-27 00:31:12
本文介绍了如何在HTTP响应中处理多个Set-Cookie标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

出于某种目的,我正在尝试编写简单的代理服务器.在其中,我使用httplib访问远程Web服务器.但是有一个问题:Web服务器在一个响应中返回两个Set-Cookie标头,而httplib在httplib.HTTPResponse.getheaders()中将它们组合在一起,有效地用逗号将cookie连接起来[这很奇怪,因为getheader返回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)?

推荐答案

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.

更多推荐

如何在HTTP响应中处理多个Set

本文发布于:2023-10-29 10:36:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539464.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   如何在   HTTP   Set

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!