From 588b48b2cd246d2644cbbb86f31b1b01e553a0ac Mon Sep 17 00:00:00 2001 From: "Paul J. Davis" Date: Wed, 10 Feb 2010 10:55:09 -0500 Subject: [PATCH] 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. --- gunicorn/http/parser.py | 6 +++++- tests/001-test-parser.py | 14 ++++++++++++++ tests/requests/017.http | 4 ++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/requests/017.http diff --git a/gunicorn/http/parser.py b/gunicorn/http/parser.py index aa934d04..3e47ec2a 100644 --- a/gunicorn/http/parser.py +++ b/gunicorn/http/parser.py @@ -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 diff --git a/tests/001-test-parser.py b/tests/001-test-parser.py index 63d99939..81b41e9e 100644 --- a/tests/001-test-parser.py +++ b/tests/001-test-parser.py @@ -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")]) diff --git a/tests/requests/017.http b/tests/requests/017.http new file mode 100644 index 00000000..bcbe3cf5 --- /dev/null +++ b/tests/requests/017.http @@ -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