summaryrefslogtreecommitdiff
path: root/urllib3/util/retry.py
diff options
context:
space:
mode:
Diffstat (limited to 'urllib3/util/retry.py')
-rw-r--r--urllib3/util/retry.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/urllib3/util/retry.py b/urllib3/util/retry.py
index f8f21810..edbfc873 100644
--- a/urllib3/util/retry.py
+++ b/urllib3/util/retry.py
@@ -13,7 +13,6 @@ from ..exceptions import (
)
from ..packages import six
-
log = logging.getLogger(__name__)
# Data structure for representing the metadata of requests that result in a retry.
@@ -21,6 +20,9 @@ RequestHistory = namedtuple('RequestHistory', ["method", "url", "error",
"status", "redirect_location"])
+_POST_REDIRECT_DOWNGRADE_STATUSES = set([301, 302, 303])
+
+
class Retry(object):
""" Retry configuration.
@@ -311,6 +313,20 @@ class Retry(object):
'read={self.read}, redirect={self.redirect})').format(
cls=type(self), self=self)
+ def redirect_method(self, method, status):
+ """
+ Assuming we're doing a redirect, should we change HTTP methods?
+ """
+ if method == 'GET':
+ return method
+ if method == 'HEAD':
+ return method
+ if status == 303:
+ return 'GET'
+ if method == 'POST' and status in _POST_REDIRECT_DOWNGRADE_STATUSES:
+ return 'GET'
+ return method
+
# For backwards compatibility (equivalent to pre-v1.9):
Retry.DEFAULT = Retry(3)