moving implementation details into util func

This commit is contained in:
Nate Prewitt
2016-07-16 10:37:13 -04:00
parent fd4332916f
commit c418c4c4aa
2 changed files with 13 additions and 2 deletions
+2 -2
View File
@@ -29,7 +29,7 @@ from .adapters import HTTPAdapter
from .utils import (
requote_uri, get_environ_proxies, get_netrc_auth, should_bypass_proxies,
get_auth_from_url
get_auth_from_url, is_valid_location
)
from .status_codes import codes
@@ -99,7 +99,7 @@ class SessionRedirectMixin(object):
request = response.request
while response.is_redirect:
if len(response.raw.headers.getlist('location')) > 1:
if not is_valid_location(response):
raise InvalidHeader('Response contains multiple Location headers. '
'Unable to perform redirect.')
+11
View File
@@ -665,6 +665,17 @@ def parse_header_links(value):
return links
def is_valid_location(response):
"""Verify that multiple Location headers weren't
returned from the last response.
"""
headers = getattr(response.raw, 'headers', None)
if headers is not None:
getlist = getattr(headers, 'getlist', None)
if getlist is not None:
return len(getlist('location')) <= 1
# If response.raw isn't urllib3-like we can't reliably check this
return True
# Null bytes; no need to recreate these on each call to guess_json_utf
_null = '\x00'.encode('ascii') # encoding to ASCII for Python 3