Skip to content

Commit

Permalink
🐛 Fixed compatibility with older PyPy 3.7 interpreters when HTTP/3 (q…
Browse files Browse the repository at this point in the history
…h3) can be unavailable. (#56)

w/ fixed undesired DGRAM/QUIC preemptive upgrade using insecure
protocol.
  • Loading branch information
Ousret authored Jan 1, 2024
1 parent eba8a30 commit 72da7f7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2.4.902 (2024-01-01)
====================

- Fixed compatibility with older PyPy 3.7 interpreters when HTTP/3 (qh3) can be unavailable.
- Fixed undesired DGRAM/QUIC preemptive upgrade using insecure protocol.

2.4.901 (2023-12-31)
====================

Expand Down
2 changes: 1 addition & 1 deletion src/urllib3/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file is protected via CODEOWNERS
from __future__ import annotations

__version__ = "2.4.901"
__version__ = "2.4.902"
9 changes: 7 additions & 2 deletions src/urllib3/backend/hface.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
from .._typing import _TYPE_SOCKET_OPTIONS

_HAS_SYS_AUDIT = hasattr(sys, "audit")
_HAS_QH3 = HTTPProtocolFactory.has(HTTP3Protocol) # type: ignore[type-abstract]
_HAS_HTTP3_SUPPORT = HTTPProtocolFactory.has(HTTP3Protocol) # type: ignore[type-abstract]


class HfaceBackend(BaseBackend):
Expand All @@ -80,6 +80,11 @@ def __init__(
disabled_svn: set[HttpVersion] | None = None,
preemptive_quic_cache: QuicPreemptiveCacheType | None = None,
):
if not _HAS_HTTP3_SUPPORT:
if disabled_svn is None:
disabled_svn = set()
disabled_svn.add(HttpVersion.h3)

super().__init__(
host,
port,
Expand Down Expand Up @@ -158,7 +163,7 @@ def _upgrade(self) -> None:
assert self.sock is not None
assert self._svn is not None

if not _HAS_QH3:
if not _HAS_HTTP3_SUPPORT:
return

# do not upgrade if not coming from TLS already.
Expand Down
3 changes: 2 additions & 1 deletion src/urllib3/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ def _new_conn(self) -> socket.socket:
source_address=self.source_address,
socket_options=self.socket_options,
socket_kind=self.socket_kind,
quic_upgrade_via_dns_rr=HttpVersion.h3 not in self._disabled_svn
quic_upgrade_via_dns_rr=self.scheme == "https"
and HttpVersion.h3 not in self._disabled_svn
and self.socket_kind != socket.SOCK_DGRAM,
timing_hook=lambda _: setattr(self, "_connect_timings", _),
default_socket_family=self._socket_family,
Expand Down

0 comments on commit 72da7f7

Please sign in to comment.