如何在HTTP响应中处理多个Set-Cookie标头 [英] How to handle multiple Set-Cookie header in HTTP response

查看:461
本文介绍了如何在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-Cookie标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆