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

Ignore 304/204 response body #549

Merged
merged 2 commits into from
Oct 4, 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
6 changes: 5 additions & 1 deletion aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,10 @@ def _setup_connection(self, connection):
self.content = self.flow_control_class(
connection.reader, loop=connection.loop)

def _need_parse_response_body(self):
return (self.method.lower() != 'head' and
self.status not in [204, 304])

@asyncio.coroutine
def start(self, connection, read_until_eof=False):
"""Start response processing."""
Expand Down Expand Up @@ -610,7 +614,7 @@ def start(self, connection, read_until_eof=False):
self.headers = CIMultiDictProxy(message.headers)

# payload
response_with_body = self.method.lower() != 'head'
response_with_body = self._need_parse_response_body()
self._reader.set_parser(
aiohttp.HttpPayloadParser(message,
readall=read_until_eof,
Expand Down
42 changes: 42 additions & 0 deletions tests/test_client_functional_newstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,45 @@ def go():
connector.close()

self.loop.run_until_complete(go())

def test_HTTP_304(self):
@asyncio.coroutine
def handler(request):
body = yield from request.read()
self.assertEqual(b'', body)
return web.Response(status=304)

@asyncio.coroutine
def go():
_, srv, url = yield from self.create_server('GET', '/', handler)
connector = aiohttp.TCPConnector(loop=self.loop)
r = yield from client.request('GET', url,
connector=connector, loop=self.loop)
content = yield from r.read()
self.assertEqual(r.status, 304)
self.assertEqual(content, b'')
r.release()
connector.close()

self.loop.run_until_complete(go())

def test_HTTP_304_WITH_BODY(self):
@asyncio.coroutine
def handler(request):
body = yield from request.read()
self.assertEqual(b'', body)
return web.Response(body=b'test', status=304)

@asyncio.coroutine
def go():
_, srv, url = yield from self.create_server('GET', '/', handler)
connector = aiohttp.TCPConnector(loop=self.loop)
r = yield from client.request('GET', url,
connector=connector, loop=self.loop)
content = yield from r.read()
self.assertEqual(r.status, 304)
self.assertEqual(content, b'')
r.release()
connector.close()

self.loop.run_until_complete(go())