Handle 301s 'properly'.

This commit is contained in:
Cory Benfield
2013-11-24 11:09:00 +00:00
parent 3327652623
commit 470af31f4a
+7 -1
View File
@@ -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