response_httprepr: fixed error with unknown response codes (closes #169)

This commit is contained in:
Pablo Hoffman 2010-06-27 19:32:26 -03:00
parent 2571e1b7aa
commit 22555df56a
2 changed files with 4 additions and 1 deletions

View File

@ -129,6 +129,9 @@ class ResponseUtilsTest(unittest.TestCase):
r1 = Response("http://www.example.com", status=404, headers={"Content-type": "text/html"}, body="Some body")
self.assertEqual(response_httprepr(r1), 'HTTP/1.1 404 Not Found\r\nContent-Type: text/html\r\n\r\nSome body')
r1 = Response("http://www.example.com", status=6666, headers={"Content-type": "text/html"}, body="Some body")
self.assertEqual(response_httprepr(r1), 'HTTP/1.1 6666 \r\nContent-Type: text/html\r\n\r\nSome body')
def test_get_cached_beautifulsoup(self):
r1 = Response('http://www.example.com', body='')

View File

@ -85,7 +85,7 @@ def response_httprepr(response):
that was received (that's not exposed by Twisted).
"""
s = "HTTP/1.1 %d %s\r\n" % (response.status, RESPONSES[response.status])
s = "HTTP/1.1 %d %s\r\n" % (response.status, RESPONSES.get(response.status, ''))
if response.headers:
s += response.headers.to_string() + "\r\n"
s += "\r\n"