Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure changes to the status attribute are written to the transport. #656

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions aiohttp/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,12 +830,18 @@ def __init__(self, transport, status,
super().__init__(transport, http_version, close)

self.status = status
if reason is None:
reason = self.calc_reason(status)
self.custom_reason = reason

self.reason = reason
self.status_line = 'HTTP/{}.{} {} {}\r\n'.format(
http_version[0], http_version[1], status, reason)
@property
def reason(self):
if self.custom_reason is not None:
return self.custom_reason
return self.calc_reason(self.status)

@property
def status_line(self):
return 'HTTP/{}.{} {} {}\r\n'.format(
self.version[0], self.version[1], self.status, self.reason)

def _add_default_headers(self):
super()._add_default_headers()
Expand All @@ -861,5 +867,8 @@ def __init__(self, transport, method, path,

self.method = method
self.path = path
self.status_line = '{0} {1} HTTP/{2[0]}.{2[1]}\r\n'.format(
method, path, http_version)

@property
def status_line(self):
return '{0} {1} HTTP/{2[0]}.{2[1]}\r\n'.format(
self.method, self.path, self.version)
13 changes: 13 additions & 0 deletions tests/test_http_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ def setUp(self):
self.transport = unittest.mock.Mock()
asyncio.set_event_loop(None)

def test_status_line_request(self):
msg = protocol.Request(
self.transport, 'GET', '/index.html', close=True)
self.assertEqual(msg.status_line, 'GET /index.html HTTP/1.1\r\n')
msg.path = '/not-index.html'
self.assertEqual(msg.status_line, 'GET /not-index.html HTTP/1.1\r\n')

def test_status_line_response(self):
msg = protocol.Response(self.transport, 200, close=True)
self.assertEqual(msg.status_line, 'HTTP/1.1 200 OK\r\n')
msg.status = 400
self.assertEqual(msg.status_line, 'HTTP/1.1 400 Bad Request\r\n')

def test_start_request(self):
msg = protocol.Request(
self.transport, 'GET', '/index.html', close=True)
Expand Down