Skip to content

Commit

Permalink
Stop casting request headers to HTTPHeaderDict (#3344)
Browse files Browse the repository at this point in the history
While this was done to fix a mypy error, we did not notice the
consequences:

 * This breaks boto3 that subclasses HTTPConnection because
   HTTPHeaderDict does not support bytes values yet.
 * When proxying, headers are still a dictionary by default.

We can decide to reintroduce a forced conversion to HTTPHeaderDict in
urllib3 3.0 if the above issues are fixed.
  • Loading branch information
pquentin committed Feb 16, 2024
1 parent e22f651 commit 49b2dda
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/3343.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed ``HTTPConnectionPool.urlopen`` to stop automatically casting non-proxy headers to ``HTTPHeaderDict``. This change was premature as it did not apply to proxy headers and ``HTTPHeaderDict`` does not handle byte header values correctly yet.
4 changes: 2 additions & 2 deletions src/urllib3/connectionpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,8 @@ def urlopen( # type: ignore[override]
# have to copy the headers dict so we can safely change it without those
# changes being reflected in anyone else's copy.
if not http_tunnel_required:
headers = HTTPHeaderDict(headers)
headers.update(self.proxy_headers)
headers = headers.copy() # type: ignore[attr-defined]
headers.update(self.proxy_headers) # type: ignore[union-attr]

# Must keep the exception bound to a separate variable or else Python 3
# complains about UnboundLocalError.
Expand Down

0 comments on commit 49b2dda

Please sign in to comment.