Skip to content

Commit

Permalink
Merge pull request #391 from nwlunatic/master
Browse files Browse the repository at this point in the history
fix request content-length header erasing after post redirect
  • Loading branch information
asvetlov committed Jun 6, 2015
2 parents 00d6180 + 907d52b commit fccf75a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ def request(self, method, url, *,
if resp.status != 307:
method = hdrs.METH_GET
data = None
if headers.get(hdrs.CONTENT_LENGTH):
headers.pop(hdrs.CONTENT_LENGTH)

r_url = (resp.headers.get(hdrs.LOCATION) or
resp.headers.get(hdrs.URI))
Expand Down
16 changes: 16 additions & 0 deletions tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,22 @@ def test_HTTP_302_REDIRECT_POST(self):
self.assertEqual(2, httpd['redirects'])
r.close()

def test_HTTP_302_REDIRECT_POST_with_content_length_header(self):
data = json.dumps({'some': 'data'})
with test_utils.run_server(self.loop, router=Functional) as httpd:
r = self.loop.run_until_complete(
client.request('post', httpd.url('redirect', 2),
data=data,
headers={'Content-Length': str(len(data))},
loop=self.loop))
content = self.loop.run_until_complete(r.content.read())
content = content.decode()

self.assertEqual(r.status, 200)
self.assertIn('"method": "GET"', content)
self.assertEqual(2, httpd['redirects'])
r.close()

def test_HTTP_307_REDIRECT_POST(self):
with test_utils.run_server(self.loop, router=Functional) as httpd:
r = self.loop.run_until_complete(
Expand Down

0 comments on commit fccf75a

Please sign in to comment.