diff options
| author | Ian Stapleton Cordasco <graffatcolmingov@gmail.com> | 2020-12-12 11:29:02 -0600 |
|---|---|---|
| committer | Ian Stapleton Cordasco <graffatcolmingov@gmail.com> | 2020-12-25 09:41:39 -0600 |
| commit | 6ab16db7bd55bc63dca2b6ef8ad04d37117927af (patch) | |
| tree | 79832bc6977db0a1c19923e0d6df76760af2289b /requests/models.py | |
| parent | d3e0f73354051f824cae563aeae215006158da28 (diff) | |
| download | python-requests-bug/5671.tar.gz | |
Pass urllib3.SKIP_HEADER when headers should be unsetbug/5671
urllib3 introduced some default headers and a way to skip them if
desired. Let's use that sentinel value to pass along information about
Requests' users desire to skip those headers as well.
Closes gh-5671
Diffstat (limited to 'requests/models.py')
| -rw-r--r-- | requests/models.py | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/requests/models.py b/requests/models.py index ec2edc20..a5c0c8b7 100644 --- a/requests/models.py +++ b/requests/models.py @@ -15,6 +15,7 @@ import sys # such as in Embedded Python. See https://github.com/psf/requests/issues/3578. import encodings.idna +import urllib3 from urllib3.fields import RequestField from urllib3.filepost import encode_multipart_formdata from urllib3.util import parse_url @@ -36,9 +37,21 @@ from .utils import ( stream_decode_response_unicode, to_key_val_list, parse_header_links, iter_slices, guess_json_utf, super_len, check_header_validity) from .compat import ( - Callable, Mapping, - cookielib, urlunparse, urlsplit, urlencode, str, bytes, - is_py2, chardet, builtin_str, basestring) + SKIP_HEADER, + SKIPPABLE_HEADERS, + Callable, + Mapping, + cookielib, + urlunparse, + urlsplit, + urlencode, + str, + bytes, + is_py2, + chardet, + builtin_str, + basestring, +) from .compat import json as complexjson from .status_codes import codes @@ -447,9 +460,14 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin): self.headers = CaseInsensitiveDict() if headers: for header in headers.items(): + name, value = header + if value is None: + if name.lower() in SKIPPABLE_HEADERS: + value = SKIP_HEADER + else: + continue # Raise exception on invalid header value. check_header_validity(header) - name, value = header self.headers[to_native_string(name)] = value def prepare_body(self, data, files, json=None): |
