httpcore2 2.15.1__tar.gz → 2.16.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. {httpcore2-2.15.1 → httpcore2-2.16.1}/CHANGELOG.md +13 -0
  2. {httpcore2-2.15.1 → httpcore2-2.16.1}/PKG-INFO +14 -1
  3. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/__init__.py +2 -2
  4. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_api.py +5 -5
  5. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_async/connection.py +7 -6
  6. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_async/connection_pool.py +8 -7
  7. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_async/http11.py +5 -5
  8. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_async/http2.py +54 -54
  9. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_async/http_proxy.py +10 -14
  10. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_async/interfaces.py +4 -6
  11. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_backends/anyio.py +7 -5
  12. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_backends/auto.py +5 -4
  13. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_backends/base.py +9 -8
  14. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_backends/mock.py +9 -8
  15. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_backends/sync.py +11 -10
  16. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_backends/trio.py +7 -6
  17. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_exceptions.py +2 -3
  18. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_models.py +24 -32
  19. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_sync/connection.py +7 -6
  20. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_sync/connection_pool.py +8 -7
  21. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_sync/http11.py +5 -5
  22. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_sync/http2.py +54 -54
  23. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_sync/http_proxy.py +10 -14
  24. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_sync/interfaces.py +4 -6
  25. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_synchronization.py +9 -7
  26. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_trace.py +9 -9
  27. httpcore2-2.16.1/httpcore2/_types.py +17 -0
  28. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_utils.py +2 -2
  29. {httpcore2-2.15.1 → httpcore2-2.16.1}/.gitignore +0 -0
  30. {httpcore2-2.15.1 → httpcore2-2.16.1}/LICENSE.md +0 -0
  31. {httpcore2-2.15.1 → httpcore2-2.16.1}/README.md +0 -0
  32. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_async/__init__.py +4 -4
  33. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_async/socks_proxy.py +0 -0
  34. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_backends/__init__.py +0 -0
  35. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_ssl.py +0 -0
  36. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_sync/__init__.py +4 -4
  37. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/_sync/socks_proxy.py +0 -0
  38. {httpcore2-2.15.1 → httpcore2-2.16.1}/httpcore2/py.typed +0 -0
  39. {httpcore2-2.15.1 → httpcore2-2.16.1}/pyproject.toml +0 -0
@@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6
6
 
7
+ ## 2.16.1 (November 16th, 2026)
8
+
9
+ ### Fixed
10
+
11
+ * Recheck the HTTP/2 flow control window after acquiring the read lock. Concurrent uploads on one connection could stall until the read timeout once the window was exhausted.
12
+ ([#1163](https://github.com/pydantic/httpx2/pull/1163))
13
+ * Raise `LocalProtocolError` instead of `IndexError` when an HTTP/2 request sent directly to a connection has no `Host` header.
14
+ ([#1319](https://github.com/pydantic/httpx2/pull/1319))
15
+
16
+ ## 2.16.0 (October 21st, 2026)
17
+
18
+ No changes since `2.15.1`. Version bumped to stay in lockstep with `httpx2`.
19
+
7
20
  ## 2.15.1 (October 19th, 2026)
8
21
 
9
22
  ### Fixed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: httpcore2
3
- Version: 2.15.1
3
+ Version: 2.16.1
4
4
  Summary: A minimal low-level HTTP client.
5
5
  Project-URL: Changelog, https://github.com/pydantic/httpx2/blob/main/src/httpcore2/CHANGELOG.md
6
6
  Project-URL: Homepage, https://github.com/pydantic/httpx2
@@ -151,6 +151,19 @@ All notable changes to this project will be documented in this file.
151
151
 
152
152
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
153
153
 
154
+ ## 2.16.1 (November 16th, 2026)
155
+
156
+ ### Fixed
157
+
158
+ * Recheck the HTTP/2 flow control window after acquiring the read lock. Concurrent uploads on one connection could stall until the read timeout once the window was exhausted.
159
+ ([#1163](https://github.com/pydantic/httpx2/pull/1163))
160
+ * Raise `LocalProtocolError` instead of `IndexError` when an HTTP/2 request sent directly to a connection has no `Host` header.
161
+ ([#1319](https://github.com/pydantic/httpx2/pull/1319))
162
+
163
+ ## 2.16.0 (October 21st, 2026)
164
+
165
+ No changes since `2.15.1`. Version bumped to stay in lockstep with `httpx2`.
166
+
154
167
  ## 2.15.1 (October 19th, 2026)
155
168
 
156
169
  ### Fixed
@@ -11,7 +11,6 @@ from ._async import (
11
11
  AsyncSOCKSProxy,
12
12
  )
13
13
  from ._backends.base import (
14
- SOCKET_OPTION,
15
14
  AsyncNetworkBackend,
16
15
  AsyncNetworkStream,
17
16
  NetworkBackend,
@@ -47,6 +46,7 @@ from ._sync import (
47
46
  HTTPProxy,
48
47
  SOCKSProxy,
49
48
  )
49
+ from ._types import SOCKET_OPTION
50
50
 
51
51
  # The 'httpcore2.AnyIOBackend' class is conditional on 'anyio' being installed.
52
52
  try:
@@ -70,7 +70,7 @@ except ImportError: # pragma: no cover
70
70
  raise RuntimeError(msg)
71
71
 
72
72
 
73
- __all__ = [
73
+ __all__ = [ # noqa: RUF022
74
74
  # top-level requests
75
75
  "request",
76
76
  "stream",
@@ -1,11 +1,11 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import contextlib
4
- import typing
5
- from collections.abc import Generator
4
+ from collections.abc import Generator, Iterator
6
5
 
7
- from ._models import URL, Extensions, HeaderTypes, Response
6
+ from ._models import URL, Response
8
7
  from ._sync.connection_pool import ConnectionPool
8
+ from ._types import Extensions, HeaderTypes
9
9
 
10
10
 
11
11
  def request(
@@ -13,7 +13,7 @@ def request(
13
13
  url: URL | bytes | str,
14
14
  *,
15
15
  headers: HeaderTypes = None,
16
- content: bytes | typing.Iterator[bytes] | None = None,
16
+ content: bytes | Iterator[bytes] | None = None,
17
17
  extensions: Extensions | None = None,
18
18
  ) -> Response:
19
19
  """
@@ -54,7 +54,7 @@ def stream(
54
54
  url: URL | bytes | str,
55
55
  *,
56
56
  headers: HeaderTypes = None,
57
- content: bytes | typing.Iterator[bytes] | None = None,
57
+ content: bytes | Iterator[bytes] | None = None,
58
58
  extensions: Extensions | None = None,
59
59
  ) -> Generator[Response]:
60
60
  """
@@ -4,15 +4,17 @@ import itertools
4
4
  import logging
5
5
  import ssl
6
6
  import types
7
- import typing
7
+ from collections.abc import Iterable, Iterator
8
+ from typing import Self
8
9
 
9
10
  from .._backends.auto import AutoBackend
10
- from .._backends.base import SOCKET_OPTION, AsyncNetworkBackend, AsyncNetworkStream
11
+ from .._backends.base import AsyncNetworkBackend, AsyncNetworkStream
11
12
  from .._exceptions import ConnectError, ConnectTimeout
12
13
  from .._models import Origin, Request, Response
13
14
  from .._ssl import default_ssl_context
14
15
  from .._synchronization import AsyncLock
15
16
  from .._trace import Trace
17
+ from .._types import SOCKET_OPTION
16
18
  from .http11 import AsyncHTTP11Connection
17
19
  from .interfaces import AsyncConnectionInterface
18
20
 
@@ -22,7 +24,7 @@ RETRIES_BACKOFF_FACTOR = 0.5 # 0s, 0.5s, 1s, 2s, 4s, etc.
22
24
  logger = logging.getLogger("httpcore2.connection")
23
25
 
24
26
 
25
- def exponential_backoff(factor: float) -> typing.Iterator[float]:
27
+ def exponential_backoff(factor: float) -> Iterator[float]:
26
28
  """
27
29
  Generate a geometric sequence that has a ratio of 2 and starts with 0.
28
30
 
@@ -47,7 +49,7 @@ class AsyncHTTPConnection(AsyncConnectionInterface):
47
49
  local_address: str | None = None,
48
50
  uds: str | None = None,
49
51
  network_backend: AsyncNetworkBackend | None = None,
50
- socket_options: typing.Iterable[SOCKET_OPTION] | None = None,
52
+ socket_options: Iterable[SOCKET_OPTION] | None = None,
51
53
  ) -> None:
52
54
  self._origin = origin
53
55
  self._ssl_context = ssl_context
@@ -195,8 +197,7 @@ class AsyncHTTPConnection(AsyncConnectionInterface):
195
197
 
196
198
  # These context managers are not used in the standard flow, but are
197
199
  # useful for testing or working with connection instances directly.
198
-
199
- async def __aenter__(self) -> AsyncHTTPConnection:
200
+ async def __aenter__(self) -> Self:
200
201
  return self
201
202
 
202
203
  async def __aexit__(
@@ -3,14 +3,15 @@ from __future__ import annotations
3
3
  import ssl
4
4
  import sys
5
5
  import types
6
- import typing
7
- from collections.abc import AsyncGenerator
6
+ from collections.abc import AsyncGenerator, AsyncIterable, Iterable
7
+ from typing import Self
8
8
 
9
9
  from .._backends.auto import AutoBackend
10
- from .._backends.base import SOCKET_OPTION, AsyncNetworkBackend
10
+ from .._backends.base import AsyncNetworkBackend
11
11
  from .._exceptions import ConnectionNotAvailable, UnsupportedProtocol
12
12
  from .._models import Origin, Proxy, Request, Response
13
13
  from .._synchronization import AsyncEvent, AsyncShieldCancellation, AsyncThreadLock
14
+ from .._types import SOCKET_OPTION
14
15
  from .._utils import safe_async_iterate
15
16
  from .connection import AsyncHTTPConnection
16
17
  from .interfaces import AsyncConnectionInterface, AsyncRequestInterface
@@ -58,7 +59,7 @@ class AsyncConnectionPool(AsyncRequestInterface):
58
59
  local_address: str | None = None,
59
60
  uds: str | None = None,
60
61
  network_backend: AsyncNetworkBackend | None = None,
61
- socket_options: typing.Iterable[SOCKET_OPTION] | None = None,
62
+ socket_options: Iterable[SOCKET_OPTION] | None = None,
62
63
  ) -> None:
63
64
  """
64
65
  A connection pool for making HTTP requests.
@@ -243,7 +244,7 @@ class AsyncConnectionPool(AsyncRequestInterface):
243
244
 
244
245
  # Return the response. Note that in this case we still have to manage
245
246
  # the point at which the response is closed.
246
- assert isinstance(response.stream, typing.AsyncIterable)
247
+ assert isinstance(response.stream, AsyncIterable)
247
248
  return Response(
248
249
  status=response.status,
249
250
  headers=response.headers,
@@ -381,7 +382,7 @@ class AsyncConnectionPool(AsyncRequestInterface):
381
382
  self._connections = []
382
383
  await self._close_connections(closing_connections)
383
384
 
384
- async def __aenter__(self) -> AsyncConnectionPool:
385
+ async def __aenter__(self) -> Self:
385
386
  return self
386
387
 
387
388
  async def __aexit__(
@@ -412,7 +413,7 @@ class AsyncConnectionPool(AsyncRequestInterface):
412
413
  class PoolByteStream:
413
414
  def __init__(
414
415
  self,
415
- stream: typing.AsyncIterable[bytes],
416
+ stream: AsyncIterable[bytes],
416
417
  pool_request: AsyncPoolRequest,
417
418
  pool: AsyncConnectionPool,
418
419
  ) -> None:
@@ -5,8 +5,8 @@ import logging
5
5
  import ssl
6
6
  import time
7
7
  import types
8
- import typing
9
- from collections.abc import AsyncGenerator
8
+ from collections.abc import AsyncGenerator, AsyncIterable
9
+ from typing import Any, Self
10
10
 
11
11
  import h11
12
12
 
@@ -142,7 +142,7 @@ class AsyncHTTP11Connection(AsyncConnectionInterface):
142
142
  timeouts = request.extensions.get("timeout", {})
143
143
  timeout = timeouts.get("write", None)
144
144
 
145
- assert isinstance(request.stream, typing.AsyncIterable)
145
+ assert isinstance(request.stream, AsyncIterable)
146
146
  async with safe_async_iterate(request.stream) as iterator:
147
147
  async for chunk in iterator:
148
148
  event = h11.Data(data=chunk)
@@ -286,7 +286,7 @@ class AsyncHTTP11Connection(AsyncConnectionInterface):
286
286
  # These context managers are not used in the standard flow, but are
287
287
  # useful for testing or working with connection instances directly.
288
288
 
289
- async def __aenter__(self) -> AsyncHTTP11Connection:
289
+ async def __aenter__(self) -> Self:
290
290
  return self
291
291
 
292
292
  async def __aexit__(
@@ -353,5 +353,5 @@ class AsyncHTTP11UpgradeStream(AsyncNetworkStream):
353
353
  ) -> AsyncNetworkStream:
354
354
  return await self._stream.start_tls(ssl_context, server_hostname, timeout)
355
355
 
356
- def get_extra_info(self, info: str) -> typing.Any:
356
+ def get_extra_info(self, info: str) -> Any:
357
357
  return self._stream.get_extra_info(info)
@@ -4,8 +4,8 @@ import enum
4
4
  import logging
5
5
  import time
6
6
  import types
7
- import typing
8
- from collections.abc import AsyncGenerator
7
+ from collections.abc import AsyncGenerator, AsyncIterable
8
+ from typing import Self
9
9
 
10
10
  import h2.config
11
11
  import h2.connection
@@ -152,7 +152,7 @@ class AsyncHTTP2Connection(AsyncConnectionInterface):
152
152
  "stream_id": stream_id,
153
153
  },
154
154
  )
155
- except BaseException as exc: # noqa: PIE786
155
+ except BaseException as exc:
156
156
  with AsyncShieldCancellation():
157
157
  kwargs = {"stream_id": stream_id}
158
158
  async with Trace("response_closed", logger, request, kwargs):
@@ -217,7 +217,9 @@ class AsyncHTTP2Connection(AsyncConnectionInterface):
217
217
  # In order to gracefully handle HTTP/1.1 and HTTP/2 we always require
218
218
  # HTTP/1.1 style headers, and map them appropriately if we end up on
219
219
  # an HTTP/2 connection.
220
- authority = [v for k, v in request.headers if k.lower() == b"host"][0]
220
+ authority = next((v for k, v in request.headers if k.lower() == b"host"), None)
221
+ if authority is None:
222
+ raise LocalProtocolError("Missing mandatory Host: header")
221
223
 
222
224
  headers = [
223
225
  (b":method", request.method),
@@ -245,7 +247,7 @@ class AsyncHTTP2Connection(AsyncConnectionInterface):
245
247
  if not has_body_headers(request):
246
248
  return
247
249
 
248
- assert isinstance(request.stream, typing.AsyncIterable)
250
+ assert isinstance(request.stream, AsyncIterable)
249
251
  async with safe_async_iterate(request.stream) as iterator:
250
252
  async for chunk in iterator:
251
253
  await self._send_stream_data(request, stream_id, chunk)
@@ -318,7 +320,10 @@ class AsyncHTTP2Connection(AsyncConnectionInterface):
318
320
  Will read more data from the network if required.
319
321
  """
320
322
  while not self._events.get(stream_id):
321
- await self._receive_events(request, stream_id)
323
+ async with self._read_lock:
324
+ if not self._events.get(stream_id):
325
+ await self._receive_events(request, stream_id)
326
+ await self._write_outgoing_data(request)
322
327
  event = self._events[stream_id].pop(0)
323
328
  if isinstance(event, h2.events.StreamReset):
324
329
  raise RemoteProtocolError(event)
@@ -326,46 +331,39 @@ class AsyncHTTP2Connection(AsyncConnectionInterface):
326
331
 
327
332
  async def _receive_events(self, request: Request, stream_id: int | None = None) -> None:
328
333
  """
329
- Read some data from the network until we see one or more events
330
- for a given stream ID.
331
- """
332
- async with self._read_lock:
333
- if self._connection_terminated is not None:
334
- last_stream_id = self._connection_terminated.last_stream_id
335
- if stream_id and last_stream_id and stream_id > last_stream_id:
336
- self._request_count -= 1
337
- raise ConnectionNotAvailable()
338
- raise RemoteProtocolError(self._connection_terminated)
339
-
340
- # This conditional is a bit icky. We don't want to block reading if we've
341
- # actually got an event to return for a given stream. We need to do that
342
- # check *within* the atomic read lock. Though it also need to be optional,
343
- # because when we call it from `_wait_for_outgoing_flow` we *do* want to
344
- # block until we've available flow control, event when we have events
345
- # pending for the stream ID we're attempting to send on.
346
- if stream_id is None or not self._events.get(stream_id):
347
- events = await self._read_incoming_data(request)
348
- for event in events:
349
- if isinstance(event, h2.events.RemoteSettingsChanged):
350
- async with Trace("receive_remote_settings", logger, request) as trace:
351
- trace.return_value = event
352
-
353
- elif isinstance(
354
- event,
355
- (
356
- h2.events.ResponseReceived,
357
- h2.events.DataReceived,
358
- h2.events.StreamEnded,
359
- h2.events.StreamReset,
360
- ),
361
- ):
362
- if event.stream_id in self._events:
363
- self._events[event.stream_id].append(event)
364
-
365
- elif isinstance(event, h2.events.ConnectionTerminated):
366
- self._connection_terminated = event
334
+ Read some data from the network and dispatch the resulting events.
367
335
 
368
- await self._write_outgoing_data(request)
336
+ The caller holds `_read_lock`, re-checks what it is waiting for after
337
+ acquiring it, since another task may have read it in the meantime, and
338
+ flushes outgoing data once the lock is released.
339
+ """
340
+ if self._connection_terminated is not None:
341
+ last_stream_id = self._connection_terminated.last_stream_id
342
+ if stream_id and last_stream_id and stream_id > last_stream_id:
343
+ self._request_count -= 1
344
+ raise ConnectionNotAvailable()
345
+ raise RemoteProtocolError(self._connection_terminated)
346
+
347
+ events = await self._read_incoming_data(request)
348
+ for event in events:
349
+ if isinstance(event, h2.events.RemoteSettingsChanged):
350
+ async with Trace("receive_remote_settings", logger, request) as trace:
351
+ trace.return_value = event
352
+
353
+ elif isinstance(
354
+ event,
355
+ (
356
+ h2.events.ResponseReceived,
357
+ h2.events.DataReceived,
358
+ h2.events.StreamEnded,
359
+ h2.events.StreamReset,
360
+ ),
361
+ ):
362
+ if event.stream_id in self._events:
363
+ self._events[event.stream_id].append(event)
364
+
365
+ elif isinstance(event, h2.events.ConnectionTerminated):
366
+ self._connection_terminated = event
369
367
 
370
368
  async def _receive_remote_settings_change(self, event: h2.events.RemoteSettingsChanged) -> None:
371
369
  max_concurrent_streams = event.changed_settings.get(h2.settings.SettingCodes.MAX_CONCURRENT_STREAMS)
@@ -484,15 +482,17 @@ class AsyncHTTP2Connection(AsyncConnectionInterface):
484
482
  WindowUpdated frames have increased the flow rate.
485
483
  https://tools.ietf.org/html/rfc7540#section-6.9
486
484
  """
487
- local_flow: int = self._h2_state.local_flow_control_window(stream_id)
488
- max_frame_size: int = self._h2_state.max_outbound_frame_size
489
- flow = min(local_flow, max_frame_size)
490
- while flow <= 0:
491
- await self._receive_events(request)
492
- local_flow = self._h2_state.local_flow_control_window(stream_id)
493
- max_frame_size = self._h2_state.max_outbound_frame_size
485
+ while True:
486
+ local_flow: int = self._h2_state.local_flow_control_window(stream_id)
487
+ max_frame_size: int = self._h2_state.max_outbound_frame_size
494
488
  flow = min(local_flow, max_frame_size)
495
- return flow
489
+ if flow > 0:
490
+ return flow
491
+ async with self._read_lock:
492
+ if self._h2_state.local_flow_control_window(stream_id) > 0:
493
+ continue
494
+ await self._receive_events(request)
495
+ await self._write_outgoing_data(request)
496
496
 
497
497
  # Interface for connection pooling...
498
498
 
@@ -538,7 +538,7 @@ class AsyncHTTP2Connection(AsyncConnectionInterface):
538
538
  # These context managers are not used in the standard flow, but are
539
539
  # useful for testing or working with connection instances directly.
540
540
 
541
- async def __aenter__(self) -> AsyncHTTP2Connection:
541
+ async def __aenter__(self) -> Self:
542
542
  return self
543
543
 
544
544
  async def __aexit__(
@@ -3,9 +3,9 @@ from __future__ import annotations
3
3
  import base64
4
4
  import logging
5
5
  import ssl
6
- import typing
6
+ from collections.abc import Iterable, Sequence
7
7
 
8
- from .._backends.base import SOCKET_OPTION, AsyncNetworkBackend
8
+ from .._backends.base import AsyncNetworkBackend
9
9
  from .._exceptions import ProxyError
10
10
  from .._models import (
11
11
  URL,
@@ -19,22 +19,18 @@ from .._models import (
19
19
  from .._ssl import default_ssl_context
20
20
  from .._synchronization import AsyncLock
21
21
  from .._trace import Trace
22
+ from .._types import SOCKET_OPTION, HeadersAsMapping, HeadersAsSequence
22
23
  from .connection import AsyncHTTPConnection
23
24
  from .connection_pool import AsyncConnectionPool
24
25
  from .http11 import AsyncHTTP11Connection
25
26
  from .interfaces import AsyncConnectionInterface
26
27
 
27
- ByteOrStr = bytes | str
28
- HeadersAsSequence = typing.Sequence[tuple[ByteOrStr, ByteOrStr]]
29
- HeadersAsMapping = typing.Mapping[ByteOrStr, ByteOrStr]
30
-
31
-
32
28
  logger = logging.getLogger("httpcore2.proxy")
33
29
 
34
30
 
35
31
  def merge_headers(
36
- default_headers: typing.Sequence[tuple[bytes, bytes]] | None = None,
37
- override_headers: typing.Sequence[tuple[bytes, bytes]] | None = None,
32
+ default_headers: Sequence[tuple[bytes, bytes]] | None = None,
33
+ override_headers: Sequence[tuple[bytes, bytes]] | None = None,
38
34
  ) -> list[tuple[bytes, bytes]]:
39
35
  """
40
36
  Append default_headers and override_headers, de-duplicating if a key exists
@@ -68,7 +64,7 @@ class AsyncHTTPProxy(AsyncConnectionPool): # pragma: no cover
68
64
  local_address: str | None = None,
69
65
  uds: str | None = None,
70
66
  network_backend: AsyncNetworkBackend | None = None,
71
- socket_options: typing.Iterable[SOCKET_OPTION] | None = None,
67
+ socket_options: Iterable[SOCKET_OPTION] | None = None,
72
68
  ) -> None:
73
69
  """
74
70
  A connection pool for making HTTP requests.
@@ -131,7 +127,7 @@ class AsyncHTTPProxy(AsyncConnectionPool): # pragma: no cover
131
127
  password = enforce_bytes(proxy_auth[1], name="proxy_auth")
132
128
  userpass = username + b":" + password
133
129
  authorization = b"Basic " + base64.b64encode(userpass)
134
- self._proxy_headers = [(b"Proxy-Authorization", authorization)] + self._proxy_headers
130
+ self._proxy_headers = [(b"Proxy-Authorization", authorization), *self._proxy_headers]
135
131
 
136
132
  def create_connection(self, origin: Origin) -> AsyncConnectionInterface:
137
133
  if origin.scheme == b"http":
@@ -164,7 +160,7 @@ class AsyncForwardHTTPConnection(AsyncConnectionInterface):
164
160
  proxy_headers: HeadersAsMapping | HeadersAsSequence | None = None,
165
161
  keepalive_expiry: float | None = None,
166
162
  network_backend: AsyncNetworkBackend | None = None,
167
- socket_options: typing.Iterable[SOCKET_OPTION] | None = None,
163
+ socket_options: Iterable[SOCKET_OPTION] | None = None,
168
164
  proxy_ssl_context: ssl.SSLContext | None = None,
169
165
  ) -> None:
170
166
  self._connection = AsyncHTTPConnection(
@@ -232,12 +228,12 @@ class AsyncTunnelHTTPConnection(AsyncConnectionInterface):
232
228
  remote_origin: Origin,
233
229
  ssl_context: ssl.SSLContext | None = None,
234
230
  proxy_ssl_context: ssl.SSLContext | None = None,
235
- proxy_headers: typing.Sequence[tuple[bytes, bytes]] | None = None,
231
+ proxy_headers: Sequence[tuple[bytes, bytes]] | None = None,
236
232
  keepalive_expiry: float | None = None,
237
233
  http1: bool = True,
238
234
  http2: bool = False,
239
235
  network_backend: AsyncNetworkBackend | None = None,
240
- socket_options: typing.Iterable[SOCKET_OPTION] | None = None,
236
+ socket_options: Iterable[SOCKET_OPTION] | None = None,
241
237
  ) -> None:
242
238
  self._connection: AsyncConnectionInterface = AsyncHTTPConnection(
243
239
  origin=proxy_origin,
@@ -1,13 +1,10 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import contextlib
4
- import typing
5
- from collections.abc import AsyncGenerator
4
+ from collections.abc import AsyncGenerator, AsyncIterator
6
5
 
7
6
  from .._models import (
8
7
  URL,
9
- Extensions,
10
- HeaderTypes,
11
8
  Origin,
12
9
  Request,
13
10
  Response,
@@ -16,6 +13,7 @@ from .._models import (
16
13
  enforce_url,
17
14
  include_request_headers,
18
15
  )
16
+ from .._types import Extensions, HeaderTypes
19
17
 
20
18
 
21
19
  class AsyncRequestInterface:
@@ -25,7 +23,7 @@ class AsyncRequestInterface:
25
23
  url: URL | bytes | str,
26
24
  *,
27
25
  headers: HeaderTypes = None,
28
- content: bytes | typing.AsyncIterator[bytes] | None = None,
26
+ content: bytes | AsyncIterator[bytes] | None = None,
29
27
  extensions: Extensions | None = None,
30
28
  ) -> Response:
31
29
  # Strict type checking on our parameters.
@@ -57,7 +55,7 @@ class AsyncRequestInterface:
57
55
  url: URL | bytes | str,
58
56
  *,
59
57
  headers: HeaderTypes = None,
60
- content: bytes | typing.AsyncIterator[bytes] | None = None,
58
+ content: bytes | AsyncIterator[bytes] | None = None,
61
59
  extensions: Extensions | None = None,
62
60
  ) -> AsyncGenerator[Response]:
63
61
  # Strict type checking on our parameters.
@@ -1,7 +1,8 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import ssl
4
- import typing
4
+ from collections.abc import Iterable
5
+ from typing import Any
5
6
 
6
7
  import anyio
7
8
  import anyio.abc
@@ -16,8 +17,9 @@ from .._exceptions import (
16
17
  WriteTimeout,
17
18
  map_exceptions,
18
19
  )
20
+ from .._types import SOCKET_OPTION
19
21
  from .._utils import is_socket_readable
20
- from .base import SOCKET_OPTION, AsyncNetworkBackend, AsyncNetworkStream
22
+ from .base import AsyncNetworkBackend, AsyncNetworkStream
21
23
 
22
24
 
23
25
  class AnyIOStream(AsyncNetworkStream):
@@ -82,7 +84,7 @@ class AnyIOStream(AsyncNetworkStream):
82
84
  raise exc
83
85
  return AnyIOStream(ssl_stream)
84
86
 
85
- def get_extra_info(self, info: str) -> typing.Any:
87
+ def get_extra_info(self, info: str) -> Any:
86
88
  if info == "ssl_object":
87
89
  return self._stream.extra(anyio.streams.tls.TLSAttribute.ssl_object, None)
88
90
  if info == "client_addr":
@@ -104,7 +106,7 @@ class AnyIOBackend(AsyncNetworkBackend):
104
106
  port: int,
105
107
  timeout: float | None = None,
106
108
  local_address: str | None = None,
107
- socket_options: typing.Iterable[SOCKET_OPTION] | None = None,
109
+ socket_options: Iterable[SOCKET_OPTION] | None = None,
108
110
  ) -> AsyncNetworkStream: # pragma: no cover
109
111
  if socket_options is None:
110
112
  socket_options = []
@@ -129,7 +131,7 @@ class AnyIOBackend(AsyncNetworkBackend):
129
131
  self,
130
132
  path: str,
131
133
  timeout: float | None = None,
132
- socket_options: typing.Iterable[SOCKET_OPTION] | None = None,
134
+ socket_options: Iterable[SOCKET_OPTION] | None = None,
133
135
  ) -> AsyncNetworkStream: # pragma: no cover
134
136
  if socket_options is None:
135
137
  socket_options = []
@@ -1,9 +1,10 @@
1
1
  from __future__ import annotations
2
2
 
3
- import typing
3
+ from collections.abc import Iterable
4
4
 
5
5
  from .._synchronization import current_async_library
6
- from .base import SOCKET_OPTION, AsyncNetworkBackend, AsyncNetworkStream
6
+ from .._types import SOCKET_OPTION
7
+ from .base import AsyncNetworkBackend, AsyncNetworkStream
7
8
 
8
9
 
9
10
  class AutoBackend(AsyncNetworkBackend):
@@ -25,7 +26,7 @@ class AutoBackend(AsyncNetworkBackend):
25
26
  port: int,
26
27
  timeout: float | None = None,
27
28
  local_address: str | None = None,
28
- socket_options: typing.Iterable[SOCKET_OPTION] | None = None,
29
+ socket_options: Iterable[SOCKET_OPTION] | None = None,
29
30
  ) -> AsyncNetworkStream:
30
31
  await self._init_backend()
31
32
  return await self._backend.connect_tcp(
@@ -40,7 +41,7 @@ class AutoBackend(AsyncNetworkBackend):
40
41
  self,
41
42
  path: str,
42
43
  timeout: float | None = None,
43
- socket_options: typing.Iterable[SOCKET_OPTION] | None = None,
44
+ socket_options: Iterable[SOCKET_OPTION] | None = None,
44
45
  ) -> AsyncNetworkStream: # pragma: no cover
45
46
  await self._init_backend()
46
47
  return await self._backend.connect_unix_socket(path, timeout=timeout, socket_options=socket_options)
@@ -2,9 +2,10 @@ from __future__ import annotations
2
2
 
3
3
  import ssl
4
4
  import time
5
- import typing
5
+ from collections.abc import Iterable
6
+ from typing import Any
6
7
 
7
- SOCKET_OPTION = tuple[int, int, int] | tuple[int, int, bytes | bytearray] | tuple[int, int, None, int]
8
+ from .._types import SOCKET_OPTION
8
9
 
9
10
 
10
11
  class NetworkStream:
@@ -25,7 +26,7 @@ class NetworkStream:
25
26
  ) -> NetworkStream:
26
27
  raise NotImplementedError() # pragma: no cover
27
28
 
28
- def get_extra_info(self, info: str) -> typing.Any:
29
+ def get_extra_info(self, info: str) -> Any:
29
30
  return None # pragma: no cover
30
31
 
31
32
 
@@ -36,7 +37,7 @@ class NetworkBackend:
36
37
  port: int,
37
38
  timeout: float | None = None,
38
39
  local_address: str | None = None,
39
- socket_options: typing.Iterable[SOCKET_OPTION] | None = None,
40
+ socket_options: Iterable[SOCKET_OPTION] | None = None,
40
41
  ) -> NetworkStream:
41
42
  raise NotImplementedError() # pragma: no cover
42
43
 
@@ -44,7 +45,7 @@ class NetworkBackend:
44
45
  self,
45
46
  path: str,
46
47
  timeout: float | None = None,
47
- socket_options: typing.Iterable[SOCKET_OPTION] | None = None,
48
+ socket_options: Iterable[SOCKET_OPTION] | None = None,
48
49
  ) -> NetworkStream:
49
50
  raise NotImplementedError() # pragma: no cover
50
51
 
@@ -70,7 +71,7 @@ class AsyncNetworkStream:
70
71
  ) -> AsyncNetworkStream:
71
72
  raise NotImplementedError() # pragma: no cover
72
73
 
73
- def get_extra_info(self, info: str) -> typing.Any:
74
+ def get_extra_info(self, info: str) -> Any:
74
75
  return None # pragma: no cover
75
76
 
76
77
 
@@ -81,7 +82,7 @@ class AsyncNetworkBackend:
81
82
  port: int,
82
83
  timeout: float | None = None,
83
84
  local_address: str | None = None,
84
- socket_options: typing.Iterable[SOCKET_OPTION] | None = None,
85
+ socket_options: Iterable[SOCKET_OPTION] | None = None,
85
86
  ) -> AsyncNetworkStream:
86
87
  raise NotImplementedError() # pragma: no cover
87
88
 
@@ -89,7 +90,7 @@ class AsyncNetworkBackend:
89
90
  self,
90
91
  path: str,
91
92
  timeout: float | None = None,
92
- socket_options: typing.Iterable[SOCKET_OPTION] | None = None,
93
+ socket_options: Iterable[SOCKET_OPTION] | None = None,
93
94
  ) -> AsyncNetworkStream:
94
95
  raise NotImplementedError() # pragma: no cover
95
96