From aaa1294feb82c97aa4291ca6183e1fbd267c36f5 Mon Sep 17 00:00:00 2001 From: Nate Prewitt Date: Wed, 10 Aug 2016 09:42:26 -0600 Subject: [PATCH] #3490 removing Content-Type and Transfer-Encoding headers on redirect --- requests/sessions.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/requests/sessions.py b/requests/sessions.py index 8d8d9105b8..08c3faeb99 100644 --- a/requests/sessions.py +++ b/requests/sessions.py @@ -138,10 +138,13 @@ def resolve_redirects(self, resp, req, stream=False, timeout=None, self.rebuild_method(prepared_request, resp) - # https://github.com/kennethreitz/requests/issues/1084 + # See https://github.com/kennethreitz/requests/issues/1084 + # and https://github.com/kennethreitz/requests/issues/3490 if resp.status_code not in (codes.temporary_redirect, codes.permanent_redirect): - if 'Content-Length' in prepared_request.headers: - del prepared_request.headers['Content-Length'] + purged_headers = ('Content-Length', 'Content-Type', 'Transfer-Encoding') + for header in purged_headers: + if header in prepared_request.headers: + del prepared_request.headers[header] prepared_request.body = None