mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
moving implementation details into util func
This commit is contained in:
@@ -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.')
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user