Comma separate repeated request headers.

RFC 2616 says that only headers that are allowed to have comma separated
values are acceptable for repetition. Though it doesn't specify an error
condition for that situation. I reckon the cleanest way would be to list
the headers that are acceptable for repetition, and return a 400 Bad
Request.
This commit is contained in:
Paul J. Davis 2010-02-10 10:55:09 -05:00
parent 61840c3707
commit 588b48b2cd
3 changed files with 23 additions and 1 deletions

View File

@ -96,7 +96,11 @@ class Parser(object):
""" parse header line"""
name, value = line.split(":", 1)
name = normalize_name(name.strip())
hdrs[name] = value.rsplit("\r\n",1)[0].strip()
value = value.rsplit("\r\n",1)[0].strip()
if name in hdrs:
hdrs[name] = "%s, %s" % (hdrs[name], value)
else:
hdrs[name] = value
return name
@property

View File

@ -192,3 +192,17 @@ def test_011(buf, p):
if chunk:
body += chunk
t.eq(body, "hello world")
@t.request("017.http")
def test_017(buf, p):
headers = []
i = p.filter_headers(headers, buf)
t.ne(i, -1)
t.eq(p.method, "GET")
t.eq(p.version, (1, 0))
t.eq(p.path, "/stuff/here")
t.eq(p.query_string, "foo=bar")
t.eq(p.is_chunked, False)
t.eq(p._chunk_eof, False)
t.eq(p.body_eof(), True)
t.eq(p.headers, [("If-Match", "bazinga!, large-sound")])

4
tests/requests/017.http Normal file
View File

@ -0,0 +1,4 @@
GET /stuff/here?foo=bar HTTP/1.0\r\n
If-Match: bazinga!\r\n
If-Match: large-sound\r\n
\r\n