From: Cory Benfield Date: Sun, 24 Nov 2013 11:09:00 +0000 (+0000) Subject: Handle 301s 'properly'. X-Git-Tag: upstream/2.2.1~35^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=470af31f4a5e9edfae1c818f5104ee83f5f541cb;p=platform%2Fupstream%2Fpython-requests.git Handle 301s 'properly'. --- diff --git a/requests/sessions.py b/requests/sessions.py index 8aff591..c0a0e85 100644 --- a/requests/sessions.py +++ b/requests/sessions.py @@ -112,10 +112,16 @@ class SessionRedirectMixin(object): method = 'GET' # Do what the browsers do, despite standards... - if (resp.status_code in (codes.moved, codes.found) and + # First, turn 302s into GETs. + if (resp.status_code == codes.found and method not in ('GET', 'HEAD')): method = 'GET' + # Second, if a POST is responded to with a 301, turn it into a GET. + # This bizarre behaviour is explained in Issue 1704. + if (resp.status_code == codes.moved) and (method == 'POST'): + method = 'GET' + prepared_request.method = method # https://github.com/kennethreitz/requests/issues/1084