Skip to content

Commit

Permalink
Merge pull request #405 from noplay/garbage_request
Browse files Browse the repository at this point in the history
Return a 400 if server received a non HTTP content
  • Loading branch information
asvetlov committed Jun 9, 2015
2 parents 3aa335c + f35a1be commit 24fe36c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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

0 comments on commit 24fe36c

Please sign in to comment.