Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
carlcarl committed Oct 3, 2015
1 parent 04191d9 commit 6afa9fb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
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
44 changes: 44 additions & 0 deletions tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,36 @@ def go():
yield from asyncio.sleep(0, loop=self.loop)
self.loop.run_until_complete(go())

def test_HTTP_304(self):
with test_utils.run_server(self.loop, router=Functional) as httpd:
@asyncio.coroutine
def go():
r = yield from client.request(
'get', httpd.url('not_modified_304', 0),
loop=self.loop)
content = yield from r.content.read()
content = content.decode()

self.assertEqual(r.status, 304)
self.assertEqual('', content)
r.close()
self.loop.run_until_complete(go())

def test_HTTP_304_WITH_BODY(self):
with test_utils.run_server(self.loop, router=Functional) as httpd:
@asyncio.coroutine
def go():
r = yield from client.request(
'get', httpd.url('not_modified_304', 1),
loop=self.loop)
content = yield from r.content.read()
content = content.decode()

self.assertEqual(r.status, 304)
self.assertEqual('', content)
r.close()
self.loop.run_until_complete(go())

def test_POST_DATA(self):
with test_utils.run_server(self.loop, router=Functional) as httpd:
url = httpd.url('method', 'post')
Expand Down Expand Up @@ -1312,6 +1342,20 @@ def redirect_307(self, match):
self._start_response(307),
headers={'Location': self._path})

@test_utils.Router.define('/not_modified_304/([0-9]+)$')
def not_modified_304(self, match):
no = int(match.group(1).upper())

if no == 0:
self._response(
self._start_response(304),
body='test',
)
else:
self._response(
self._start_response(304),
)

@test_utils.Router.define('/encoding/(gzip|deflate)$')
def encoding(self, match):
mode = match.group(1)
Expand Down

0 comments on commit 6afa9fb

Please sign in to comment.