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

Return a 400 if server received a non HTTP content #405

Merged
merged 1 commit into from
Jun 9, 2015
Merged
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
2 changes: 2 additions & 0 deletions aiohttp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ def start(self):
if self.transport is not None:
yield from self.handle_error(exc.code, message,
None, exc, exc.headers)
except errors.LineLimitExceededParserError as exc:
yield from self.handle_error(400, message, None, exc)
except Exception as exc:
yield from self.handle_error(500, message, None, exc)
finally:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,17 @@ def test_bad_method(self):
self.assertTrue(transport.write.mock_calls[0][1][0].startswith(
b'HTTP/1.1 400 Bad Request\r\n'))

def test_line_too_long(self):
transport = unittest.mock.Mock()
srv = server.ServerHttpProtocol(loop=self.loop)
srv.connection_made(transport)

srv.reader.feed_data(b''.join([b'a' for _ in range(10000)]))

self.loop.run_until_complete(srv._request_handler)
self.assertTrue(transport.write.mock_calls[0][1][0].startswith(
b'HTTP/1.1 400 Bad Request\r\n'))

def test_handle_error(self):
transport = unittest.mock.Mock()
srv = server.ServerHttpProtocol(loop=self.loop)
Expand Down