Make read_headers return an ODictCaseless object.

This commit is contained in:
Aldo Cortesi 2012-06-24 21:49:23 +12:00
parent 171de05d8e
commit 0de765f360
2 changed files with 6 additions and 5 deletions

View File

@ -1,4 +1,5 @@
import string, urlparse
import odict
class HttpError(Exception):
def __init__(self, code, msg):
@ -54,7 +55,7 @@ def read_headers(fp):
name = line[:i]
value = line[i+1:].strip()
ret.append([name, value])
return ret
return odict.ODictCaseless(ret)
def read_chunked(code, fp, limit):
@ -107,7 +108,7 @@ def has_chunked_encoding(headers):
def read_http_body(code, rfile, headers, all, limit):
"""
Read an HTTP body:
code: The HTTP error code to be used when raising HttpError
rfile: A file descriptor to read from
headers: An ODictCaseless object

View File

@ -155,7 +155,7 @@ class TestReadHeaders:
data = data.strip()
s = cStringIO.StringIO(data)
h = http.read_headers(s)
assert h == [["Header", "one"], ["Header2", "two"]]
assert h.lst == [["Header", "one"], ["Header2", "two"]]
def test_read_multi(self):
data = """
@ -167,7 +167,7 @@ class TestReadHeaders:
data = data.strip()
s = cStringIO.StringIO(data)
h = http.read_headers(s)
assert h == [["Header", "one"], ["Header", "two"]]
assert h.lst == [["Header", "one"], ["Header", "two"]]
def test_read_continued(self):
data = """
@ -180,7 +180,7 @@ class TestReadHeaders:
data = data.strip()
s = cStringIO.StringIO(data)
h = http.read_headers(s)
assert h == [["Header", "one\r\n two"], ["Header2", "three"]]
assert h.lst == [["Header", "one\r\n two"], ["Header2", "three"]]
def test_parse_url():