-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 11/27/2014 07:29 AM, Jimmy Thrasibule wrote:
> Hello,
>
> I'd like to run over the request headers and concatenate all headers
> with the same name in on string where each value is separated by a
> comma. For example:
>
> Host: example.com Content-Type: text/html Custom-Header: value1
> Custom-Header: value2 Custom-Header: value3
>
> I'd like from this have a dictionary in the following form:
>
> { 'host': 'example.com', 'content-type': 'text/html', 'custom-header':
> 'value1, value2, value3', }
>
> So I wonder how multiple headers with the same name are represented
> within Pyramid? Is it a MultiDict or a list of values?
Pyramid's request derives from WebOb's request, and uses its
EnvironHeaders. That class has the following docstring:
"""An object that represents the headers as present in a
WSGI environment.
This object is a wrapper (with no internal state) for a WSGI
request object, representing the CGI-style HTTP_* keys as a
dictionary. Because a CGI environment can only hold one value for
each key, this dictionary is single-valued (unlike outgoing
headers).
"""
So, you don't get access to the "raw" values, only what your front-end
WSGI server morphs into the CGI environment. As it happens, waitress
does exactly what you want, in conformance with RFC 2616[1], which says:
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)].
It MUST be possible to 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. The order in which header fields with the
same field-name are received is therefore significant to the
interpretation of the combined field value, and thus a proxy MUST
NOT change the order of these field values when a message is
forwarded.
The CGI spec[2] says:
If multiple headers with the same field-name are received then they
must be rewritten as a single header having the same semantics.
Similarly, a header that is received on more than one line must be
merged onto a single line. The server must, if necessary, change
the representation of the data (for example, the character set) to
be appropriate for a CGI environment variable.
[1] http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
[2] http://tools.ietf.org/html/draft-robinson-www-interface-00
Tres.
- --
===================================================================
Tres Seaver +1 540-429-0999 [email protected]
Palladion Software "Excellence by Design" http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
iEYEARECAAYFAlR6QRoACgkQ+gerLs4ltQ40aQCgqNocth024ptXPvMbaVGtCjn9
JpIAnRwYPrvI+KGsgy2K9TftqVwrgZmo
=/2Lg
-----END PGP SIGNATURE-----
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.