How to handle multiple Set-Cookie headers in an HTTP response

I am trying to write a simple proxy server for some purpose. In it, I use httplib to access the remote web server. But there is one problem: the web server returns two Set-Cookie headers in one response, and httplib combines them together in httplib.HTTPResponse.getheaders (), effectively combining cookies with a comma [which is strange because getheaders returns LIST rather than DICT, so I thought they wrote it with multiple headers with the same name). Therefore, when I send this combined header back to the client, it confuses the client. How to get a complete list of headers in httplib (without comma separated Set-Cookie headers)?

+4
source share
1 answer

HTTPResponse.getheaders() returns a list of combined headers (actually my call to dict.items() ). The only place where incoming headers are kept intact is HTTPResponse.msg.headers .

+4
source

All Articles