tags:

views:

173

answers:

2

In WSGI headers are represented in the environ as 'HTTP_XXX' values. For example the value Cookie: header is stored at the HTTP_COOKIE key of the environ.

How are multiple request headers with the same header name represented?

+2  A: 

I thought the answer to this one would be trivial, but after digging a bit I'm not so sure.

Here's what I've found so far:

The WSGI PEP-333 (http://www.python.org/dev/peps/pep-0333/) suggests that the environment variables should contain whatever the CGI specification says.

The CGI specification (getting harder to find, a lot of broken links, best I could find at draft-coar-cgi-v11-03) talks about metadata and says (section 6.1.5)

". If multiple header fields with the same field-name are received then the server MUST rewrite them as though they had been received as a single header field having the same semantics before being represented in a metavariable"

Which suggests to me that if you have multiple header lines with the same key, you must join them up somehow into one line.

HTTP_COOKIE, as an example, supports this by concatenating all the key=value pairs into one line with semicolons between them.

Colin Coghill
Original CGI spec: http://hoohoo.ncsa.illinois.edu/cgi/interface.html - reflects reality better than the coar draft.
bobince
+4  A: 

Multiple cookies are combined into a single header, separated by semicolons.

Multiple headers are allowed by the HTTP spec, but only for certain kinds of headers, and it is always permissible to combine those headers into one (though using commas, not semicolons)

inklesspen