[Web-SIG] Multiple message-header fields handling

Phillip J. Eby pje at telecommunity.com
Tue Oct 2 21:44:05 CEST 2007

At 09:30 PM 10/2/2007 +0200, Manlio Perillo wrote:
>The HTTP 1.1 protocol (section 4.2) says that:
>"""Multiple message-header fields with the same field-name MAY be
>present in a message if and only if the entire field-value for that
>header field is defined as a comma-separated list [i.e., #(values)]."""
>This can happen, as an example, with the Cookie header.
>My question is: how should this be handled in WSGI?
>As an example Nginx stores all the headers in a associative array,
>where, of course, only the "last seen" headers appears.
>However common multiple message-headers are stored in the request struct.
>Since the WSGI environment is a dictionary with keys and values of type
>str, should an implementation:
>"""combine the multiple header fields into one "field-name: field-value"
>pair, without changing the semantics of the message, by appending each
>subsequent field-value to the first, each separated by a comma."""

If that's the only way to make the headers work, then the server may do so.

>Another question: when an header has an empty field value, what should
>be set in the environment: an empty string or None?

If a value exists in the environ, it *must* be a string -- never 
None.  And if the header exists, then a value should be in the 
environ.  Therefore, it should be an empty string.

More information about the Web-SIG mailing list