From e6c4cfe8a5b1b17899b59c92de453d8ee0d0a833 Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Wed, 3 Jun 2015 17:04:36 +0600 Subject: [PATCH 1/2] fix request content-length header erasing after post redirect --- aiohttp/client.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/aiohttp/client.py b/aiohttp/client.py index 7f89e4b7a12..27a14ceb88e 100644 --- a/aiohttp/client.py +++ b/aiohttp/client.py @@ -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)) From 907d52b4762f175e5c637a3627004a6bce20da0e Mon Sep 17 00:00:00 2001 From: Igor Pavlov Date: Sat, 6 Jun 2015 17:26:34 +0600 Subject: [PATCH 2/2] add test redirect post to get with content-length header --- tests/test_client_functional.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_client_functional.py b/tests/test_client_functional.py index c6137cf0868..ff9a761d329 100644 --- a/tests/test_client_functional.py +++ b/tests/test_client_functional.py @@ -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(