Skip to content

Commit

Permalink
Exception in request handling if the server responds before the body …
Browse files Browse the repository at this point in the history
…is sent #1761
  • Loading branch information
fafhrd91 committed Mar 29, 2017
1 parent 5cff25b commit aba31f6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Changes

- Disable cleanup closed ssl transports by default.

- Exception in request handling if the server responds before the body is sent #1761


2.0.4 (2017-03-27)
------------------
Expand Down
3 changes: 2 additions & 1 deletion aiohttp/web_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,8 @@ def start(self, message, payload, handler):
now = loop.time()
end_t = now + lingering_time

with suppress(asyncio.TimeoutError):
with suppress(
asyncio.TimeoutError, asyncio.CancelledError):
while (not payload.is_eof() and now < end_t):
timeout = min(end_t - now, lingering_time)
with CeilTimeout(timeout, loop=loop):
Expand Down
19 changes: 19 additions & 0 deletions tests/test_web_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,25 @@ def handler(request):
assert '' == txt


@asyncio.coroutine
def test_response_before_complete(loop, test_client):

@asyncio.coroutine
def handler(request):
return web.Response(body=b'OK')

app = web.Application()
app.router.add_post('/', handler)
client = yield from test_client(app)

data = b'0' * 1024 * 1024

resp = yield from client.post('/', data=data)
assert 200 == resp.status
text = yield from resp.text()
assert 'OK' == text


@asyncio.coroutine
def test_post_form(loop, test_client):

Expand Down

0 comments on commit aba31f6

Please sign in to comment.