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

Fixed consecutive calls for write_eof on Response #1939

Merged
merged 9 commits into from
Jun 19, 2017
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Changes

- Add doc for add_head, update doc for add_get. #1944

- Fixed consecutive calls for `Response.write_eof`.

- Retain method attributes (e.g. :code:`__doc__`) when registering synchronous
handlers for resources. #1953

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ Pankaj Pandey
Pau Freixes
Paul Colomiets
Paulus Schoutsen
Pavel Kamaev
Pawel Miech
Philipp A.
Rafael Viotti
Expand Down
2 changes: 2 additions & 0 deletions aiohttp/web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,8 @@ def content_length(self, value):

@asyncio.coroutine
def write_eof(self):
if self._eof_sent:
return
body = self._body
if body is not None:
if (self._req._method == hdrs.METH_HEAD or
Expand Down
14 changes: 14 additions & 0 deletions tests/test_web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,20 @@ def test_send_set_cookie_header(buf, writer):
'Server: .+\r\n\r\n', txt)


@asyncio.coroutine
def test_consecutive_write_eof():
req = make_request('GET', '/')
data = b'data'
resp = Response(body=data)

yield from resp.prepare(req)
with mock.patch('aiohttp.web.StreamResponse.write_eof') as super_write_eof:
yield from resp.write_eof()
resp._eof_sent = True
yield from resp.write_eof()
super_write_eof.assert_called_once_with(data)


def test_set_text_with_content_type():
resp = Response()
resp.content_type = "text/html"
Expand Down