HTTPHeaderMap naively splits on commas #314
Description
hyper.common.headers.canonical_form
:
the header is split on commas unless for any reason it's a super-special snowflake (I'm looking at you Set-Cookie)
This seems to be inspired by text from RFC 7230 § 3.2.2, but that permits joining field-values with commas, not splitting them.
This is most readily obvious with the Date
header:
import hyper
conn = hyper.HTTPConnection('nghttp2.org:443')
conn.request('GET', '/')
print(conn.get_response().headers['Date'])
# prints: [b'Sat', b'04 Mar 2017 18:23:26 GMT']
But there’s a wealth of other examples:
WWW-Authenticate: Digest realm="test", qop="auth", nonce="12345"
Cache-Control: private, no-cache="Some-Header,Other-Header"
Warning: 299 - "something may be wrong, be careful"
One could do b','.join(headers[name])
to get back to a value that is mostly correct with regard to commas (modulo Set-Cookie
and except for lost whitespace). But maybe the API would be better if HTTPHeaderMap.__getitem__
returned a correct value by default, while splitting on commas were an explicit operation.
See also Werkzeug’s header parsing utilities, though they are far from 100% correct as well.