Skip to content

Commit 1770460

Browse files
committed
Add default plain text renderers for HTTPExceptions
1 parent 53f264c commit 1770460

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

aiohttp/web.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ def __init__(self, request, *, headers=None, reason=None):
613613
Response.__init__(self, request, status=self.status_code,
614614
headers=headers, reason=reason)
615615
Exception.__init__(self, self.reason)
616+
self.body = "{}: {}".format(self.status, self.reason).encode('utf-8')
616617

617618

618619
class HTTPError(HTTPException):

tests/test_web_exceptions.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ def test_HTTPOk(self):
5252
self.loop.run_until_complete(resp.write_eof())
5353
txt = self.buf.decode('utf8')
5454
self.assertRegex(txt, ('HTTP/1.1 200 OK\r\n'
55-
'CONTENT-LENGTH: 0\r\n'
55+
'CONTENT-LENGTH: 7\r\n'
5656
'CONNECTION: keep-alive\r\n'
5757
'DATE: .+\r\n'
58-
'SERVER: .+\r\n\r\n'))
58+
'SERVER: .+\r\n\r\n'
59+
'200: OK'))
5960

6061
def test_terminal_classes_has_status_code(self):
6162
terminals = set()
@@ -84,11 +85,12 @@ def test_HTTPFound(self):
8485
self.loop.run_until_complete(resp.write_eof())
8586
txt = self.buf.decode('utf8')
8687
self.assertRegex(txt, ('HTTP/1.1 302 Found\r\n'
87-
'CONTENT-LENGTH: 0\r\n'
88+
'CONTENT-LENGTH: 10\r\n'
8889
'LOCATION: /redirect\r\n'
8990
'CONNECTION: keep-alive\r\n'
9091
'DATE: .+\r\n'
91-
'SERVER: .+\r\n\r\n'))
92+
'SERVER: .+\r\n\r\n'
93+
'302: Found'))
9294

9395
def test_HTTPFound_empty_location(self):
9496
req = self.make_request()
@@ -108,8 +110,9 @@ def test_HTTPMethodNotAllowed(self):
108110
self.loop.run_until_complete(resp.write_eof())
109111
txt = self.buf.decode('utf8')
110112
self.assertRegex(txt, ('HTTP/1.1 405 Method Not Allowed\r\n'
111-
'CONTENT-LENGTH: 0\r\n'
113+
'CONTENT-LENGTH: 23\r\n'
112114
'ALLOW: POST,PUT\r\n'
113115
'CONNECTION: keep-alive\r\n'
114116
'DATE: .+\r\n'
115-
'SERVER: .+\r\n\r\n'))
117+
'SERVER: .+\r\n\r\n'
118+
'405: Method Not Allowed'))

tests/test_web_functional.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def go():
132132
allow_redirects=False)
133133
self.assertEqual(301, resp.status)
134134
txt = yield from resp.text()
135-
self.assertEqual('', txt)
135+
self.assertEqual('301: Moved Permanently', txt)
136136
self.assertEqual('/path', resp.headers['location'])
137137

138138
self.loop.run_until_complete(go())

0 commit comments

Comments
 (0)