mirror of
https://github.com/kennethreitz/requests3.git
synced 2026-06-05 23:10:16 +00:00
Use HTTPHeaderDict for response headers.
This commit is contained in:
@@ -31,7 +31,7 @@ from .compat import urlparse, basestring
|
||||
from .utils import (DEFAULT_CA_BUNDLE_PATH, get_encoding_from_headers,
|
||||
prepend_scheme_if_needed, get_auth_from_url, urldefragauth,
|
||||
select_proxy)
|
||||
from .structures import CaseInsensitiveDict
|
||||
from .structures import HTTPHeaderDict
|
||||
from .cookies import extract_cookies_to_jar
|
||||
from .exceptions import (ConnectionError, ConnectTimeout, ReadTimeout, SSLError,
|
||||
ProxyError, RetryError, InvalidScheme)
|
||||
@@ -274,7 +274,7 @@ class HTTPAdapter(BaseAdapter):
|
||||
response.status_code = getattr(resp, 'status', None)
|
||||
|
||||
# Make headers case-insensitive.
|
||||
response.headers = CaseInsensitiveDict(getattr(resp, 'headers', {}))
|
||||
response.headers = HTTPHeaderDict(getattr(resp, 'headers', {}))
|
||||
|
||||
# Set encoding.
|
||||
response.encoding = get_encoding_from_headers(response.headers)
|
||||
|
||||
+12
-1
@@ -2186,6 +2186,12 @@ class TestRequests:
|
||||
fruits = resp.headers['fruit']
|
||||
assert fruits == 'Apple, Blood Orange, Banana, Berry, Blue'
|
||||
|
||||
# As we are using HTTPHeaderDict, we should be able to extract the
|
||||
# individual header values too.
|
||||
assert resp.headers.multiget('fruit') == (
|
||||
'Apple', 'Blood Orange', 'Banana', 'Berry, Blue'
|
||||
)
|
||||
|
||||
def test_multiple_response_headers_with_same_name_diff_case(self, httpbin):
|
||||
# urllib3 seems to have trouble guaranteeing the order of the items when
|
||||
# the case is different, so we just need to make sure all of the items
|
||||
@@ -2196,9 +2202,14 @@ class TestRequests:
|
||||
# These are all possible acceptable combinations for the header.
|
||||
fruit_choices = ['Apple', 'Blood Orange', 'Banana', 'Berry, Blue']
|
||||
fruit_permutations = itertools.permutations(fruit_choices)
|
||||
fruit_headers = set(', '.join(fp) for fp in fruit_permutations)
|
||||
fruit_multiheaders = set(tuple(fp) for fp in fruit_permutations)
|
||||
fruit_headers = set(', '.join(fp) for fp in fruit_multiheaders)
|
||||
assert resp.headers['fruit'] in fruit_headers
|
||||
|
||||
# As we are using HTTPHeaderDict, we should be able to extract the
|
||||
# individual header values too.
|
||||
assert resp.headers.multiget('fruit') in fruit_multiheaders
|
||||
|
||||
|
||||
class TestCaseInsensitiveDict:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user