httpcore2 2.13.0__tar.gz → 2.14.0__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 (38) hide show
  1. {httpcore2-2.13.0 → httpcore2-2.14.0}/CHANGELOG.md +20 -0
  2. {httpcore2-2.13.0 → httpcore2-2.14.0}/PKG-INFO +21 -1
  3. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_async/connection.py +1 -1
  4. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_async/http2.py +29 -6
  5. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_async/http_proxy.py +10 -5
  6. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_async/socks_proxy.py +3 -1
  7. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_backends/anyio.py +1 -0
  8. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_sync/connection.py +1 -1
  9. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_sync/http2.py +29 -6
  10. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_sync/http_proxy.py +10 -5
  11. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_sync/socks_proxy.py +3 -1
  12. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_synchronization.py +25 -0
  13. {httpcore2-2.13.0 → httpcore2-2.14.0}/.gitignore +0 -0
  14. {httpcore2-2.13.0 → httpcore2-2.14.0}/LICENSE.md +0 -0
  15. {httpcore2-2.13.0 → httpcore2-2.14.0}/README.md +0 -0
  16. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/__init__.py +0 -0
  17. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_api.py +0 -0
  18. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_async/__init__.py +0 -0
  19. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_async/connection_pool.py +0 -0
  20. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_async/http11.py +0 -0
  21. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_async/interfaces.py +0 -0
  22. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_backends/__init__.py +0 -0
  23. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_backends/auto.py +0 -0
  24. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_backends/base.py +0 -0
  25. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_backends/mock.py +0 -0
  26. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_backends/sync.py +0 -0
  27. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_backends/trio.py +0 -0
  28. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_exceptions.py +0 -0
  29. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_models.py +0 -0
  30. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_ssl.py +0 -0
  31. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_sync/__init__.py +0 -0
  32. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_sync/connection_pool.py +0 -0
  33. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_sync/http11.py +0 -0
  34. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_sync/interfaces.py +0 -0
  35. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_trace.py +0 -0
  36. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/_utils.py +0 -0
  37. {httpcore2-2.13.0 → httpcore2-2.14.0}/httpcore2/py.typed +0 -0
  38. {httpcore2-2.13.0 → httpcore2-2.14.0}/pyproject.toml +0 -0
@@ -4,6 +4,26 @@ 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.14.0 (October 18th, 2026)
8
+
9
+ ### Fixed
10
+
11
+ * Keep `CONNECT` and absolute-form proxy targets when the request sets the `target` extension.
12
+ ([#1262](https://github.com/pydantic/httpx2/pull/1262))
13
+ * Stop blocking reads when an HTTP/2 server lowers `SETTINGS_MAX_CONCURRENT_STREAMS` while requests are in flight.
14
+ ([#1217](https://github.com/pydantic/httpx2/pull/1217))
15
+ * Raise `WriteError` instead of `anyio.EndOfStream` when writing after the peer closes a TLS connection without `close_notify`.
16
+ ([#1263](https://github.com/pydantic/httpx2/pull/1263))
17
+
18
+ ## 2.13.1 (September 23rd, 2026)
19
+
20
+ ### Fixed
21
+
22
+ * Honor the `sni_hostname` extension for TLS inside HTTP proxy tunnels without applying it to the proxy's TLS connection.
23
+ ([#1223](https://github.com/pydantic/httpx2/pull/1223))
24
+ * Prefer HTTP/2 during TLS protocol negotiation when enabled, and stop advertising HTTP/1.1 when it is disabled.
25
+ ([#1155](https://github.com/pydantic/httpx2/pull/1155))
26
+
7
27
  ## 2.13.0 (September 14th, 2026)
8
28
 
9
29
  ### Changed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: httpcore2
3
- Version: 2.13.0
3
+ Version: 2.14.0
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
@@ -152,6 +152,26 @@ All notable changes to this project will be documented in this file.
152
152
 
153
153
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
154
154
 
155
+ ## 2.14.0 (October 18th, 2026)
156
+
157
+ ### Fixed
158
+
159
+ * Keep `CONNECT` and absolute-form proxy targets when the request sets the `target` extension.
160
+ ([#1262](https://github.com/pydantic/httpx2/pull/1262))
161
+ * Stop blocking reads when an HTTP/2 server lowers `SETTINGS_MAX_CONCURRENT_STREAMS` while requests are in flight.
162
+ ([#1217](https://github.com/pydantic/httpx2/pull/1217))
163
+ * Raise `WriteError` instead of `anyio.EndOfStream` when writing after the peer closes a TLS connection without `close_notify`.
164
+ ([#1263](https://github.com/pydantic/httpx2/pull/1263))
165
+
166
+ ## 2.13.1 (September 23rd, 2026)
167
+
168
+ ### Fixed
169
+
170
+ * Honor the `sni_hostname` extension for TLS inside HTTP proxy tunnels without applying it to the proxy's TLS connection.
171
+ ([#1223](https://github.com/pydantic/httpx2/pull/1223))
172
+ * Prefer HTTP/2 during TLS protocol negotiation when enabled, and stop advertising HTTP/1.1 when it is disabled.
173
+ ([#1155](https://github.com/pydantic/httpx2/pull/1155))
174
+
155
175
  ## 2.13.0 (September 14th, 2026)
156
176
 
157
177
  ### Changed
@@ -128,7 +128,7 @@ class AsyncHTTPConnection(AsyncConnectionInterface):
128
128
 
129
129
  if self._origin.scheme in (b"https", b"wss"):
130
130
  ssl_context = default_ssl_context() if self._ssl_context is None else self._ssl_context
131
- alpn_protocols = ["http/1.1", "h2"] if self._http2 else ["http/1.1"]
131
+ alpn_protocols = (["h2", "http/1.1"] if self._http1 else ["h2"]) if self._http2 else ["http/1.1"]
132
132
  ssl_context.set_alpn_protocols(alpn_protocols)
133
133
 
134
134
  kwargs = {
@@ -105,13 +105,23 @@ class AsyncHTTP2Connection(AsyncConnectionInterface):
105
105
  # its max_concurrent_streams value
106
106
  self._max_streams = 1
107
107
 
108
+ # Revoked permits still held by active or queued requests.
109
+ self._max_streams_deficit = 0
110
+
108
111
  local_settings_max_streams = self._h2_state.local_settings.max_concurrent_streams
109
112
  self._max_streams_semaphore = AsyncSemaphore(local_settings_max_streams)
110
113
 
111
114
  for _ in range(local_settings_max_streams - self._max_streams):
112
115
  await self._max_streams_semaphore.acquire()
113
116
 
114
- await self._max_streams_semaphore.acquire()
117
+ # A queued request may receive a permit just before the limit drops.
118
+ while True:
119
+ await self._max_streams_semaphore.acquire()
120
+ with AsyncShieldCancellation():
121
+ async with self._state_lock:
122
+ if not self._max_streams_deficit:
123
+ break
124
+ self._max_streams_deficit -= 1
115
125
 
116
126
  try:
117
127
  stream_id = self._h2_state.get_next_available_stream_id()
@@ -338,7 +348,6 @@ class AsyncHTTP2Connection(AsyncConnectionInterface):
338
348
  for event in events:
339
349
  if isinstance(event, h2.events.RemoteSettingsChanged):
340
350
  async with Trace("receive_remote_settings", logger, request) as trace:
341
- await self._receive_remote_settings_change(event)
342
351
  trace.return_value = event
343
352
 
344
353
  elif isinstance(
@@ -366,17 +375,25 @@ class AsyncHTTP2Connection(AsyncConnectionInterface):
366
375
  self._h2_state.local_settings.max_concurrent_streams,
367
376
  )
368
377
  if new_max_streams and new_max_streams != self._max_streams:
378
+ # Never wait for permits while holding the read lock.
369
379
  while new_max_streams > self._max_streams:
370
- await self._max_streams_semaphore.release()
380
+ if self._max_streams_deficit > 0:
381
+ self._max_streams_deficit -= 1
382
+ else:
383
+ await self._max_streams_semaphore.release()
371
384
  self._max_streams += 1
372
385
  while new_max_streams < self._max_streams:
373
- await self._max_streams_semaphore.acquire()
386
+ if not self._max_streams_semaphore.acquire_if_available():
387
+ self._max_streams_deficit += 1
374
388
  self._max_streams -= 1
375
389
 
376
390
  async def _response_closed(self, stream_id: int) -> None:
377
391
  async with self._state_lock:
378
392
  if stream_id in self._events:
379
- await self._max_streams_semaphore.release()
393
+ if self._max_streams_deficit > 0:
394
+ self._max_streams_deficit -= 1
395
+ else:
396
+ await self._max_streams_semaphore.release()
380
397
  del self._events[stream_id]
381
398
  if self._connection_terminated and not self._events:
382
399
  await self.aclose()
@@ -422,7 +439,13 @@ class AsyncHTTP2Connection(AsyncConnectionInterface):
422
439
  self._connection_error = True
423
440
  raise exc
424
441
 
425
- events: list[h2.events.Event] = self._h2_state.receive_data(data)
442
+ # Apply settings and stream admission limits atomically.
443
+ with AsyncShieldCancellation():
444
+ async with self._state_lock:
445
+ events: list[h2.events.Event] = self._h2_state.receive_data(data)
446
+ for event in events:
447
+ if isinstance(event, h2.events.RemoteSettingsChanged):
448
+ await self._receive_remote_settings_change(event)
426
449
 
427
450
  return events
428
451
 
@@ -184,14 +184,16 @@ class AsyncForwardHTTPConnection(AsyncConnectionInterface):
184
184
  scheme=self._proxy_origin.scheme,
185
185
  host=self._proxy_origin.host,
186
186
  port=self._proxy_origin.port,
187
- target=bytes(request.url),
187
+ target=bytes(request.url) if request.url.target.startswith(b"/") else request.url.target,
188
188
  )
189
189
  proxy_request = Request(
190
190
  method=request.method,
191
191
  url=url,
192
192
  headers=headers,
193
193
  content=request.stream,
194
- extensions=request.extensions,
194
+ extensions={
195
+ key: value for key, value in request.extensions.items() if key not in ("sni_hostname", "target")
196
+ },
195
197
  )
196
198
  return await self._connection.handle_async_request(proxy_request)
197
199
 
@@ -274,7 +276,9 @@ class AsyncTunnelHTTPConnection(AsyncConnectionInterface):
274
276
  method=b"CONNECT",
275
277
  url=connect_url,
276
278
  headers=connect_headers,
277
- extensions=request.extensions,
279
+ extensions={
280
+ key: value for key, value in request.extensions.items() if key not in ("sni_hostname", "target")
281
+ },
278
282
  )
279
283
  connect_response = await self._connection.handle_async_request(connect_request)
280
284
 
@@ -289,12 +293,13 @@ class AsyncTunnelHTTPConnection(AsyncConnectionInterface):
289
293
 
290
294
  # Upgrade the stream to SSL
291
295
  ssl_context = default_ssl_context() if self._ssl_context is None else self._ssl_context
292
- alpn_protocols = ["http/1.1", "h2"] if self._http2 else ["http/1.1"]
296
+ alpn_protocols = (["h2", "http/1.1"] if self._http1 else ["h2"]) if self._http2 else ["http/1.1"]
293
297
  ssl_context.set_alpn_protocols(alpn_protocols)
294
298
 
299
+ server_hostname = request.extensions.get("sni_hostname") or self._remote_origin.host.decode("ascii")
295
300
  kwargs = {
296
301
  "ssl_context": ssl_context,
297
- "server_hostname": self._remote_origin.host.decode("ascii"),
302
+ "server_hostname": server_hostname,
298
303
  "timeout": timeout,
299
304
  }
300
305
  async with Trace("start_tls", logger, request, kwargs) as trace:
@@ -242,7 +242,9 @@ class AsyncSocks5Connection(AsyncConnectionInterface):
242
242
  # Upgrade the stream to SSL
243
243
  if self._remote_origin.scheme in (b"https", b"wss"):
244
244
  ssl_context = default_ssl_context() if self._ssl_context is None else self._ssl_context
245
- alpn_protocols = ["http/1.1", "h2"] if self._http2 else ["http/1.1"]
245
+ alpn_protocols = (
246
+ (["h2", "http/1.1"] if self._http1 else ["h2"]) if self._http2 else ["http/1.1"]
247
+ )
246
248
  ssl_context.set_alpn_protocols(alpn_protocols)
247
249
 
248
250
  kwargs = {
@@ -46,6 +46,7 @@ class AnyIOStream(AsyncNetworkStream):
46
46
  TimeoutError: WriteTimeout,
47
47
  anyio.BrokenResourceError: WriteError,
48
48
  anyio.ClosedResourceError: WriteError,
49
+ anyio.EndOfStream: WriteError,
49
50
  }
50
51
  with map_exceptions(exc_map):
51
52
  with anyio.fail_after(timeout):
@@ -128,7 +128,7 @@ class HTTPConnection(ConnectionInterface):
128
128
 
129
129
  if self._origin.scheme in (b"https", b"wss"):
130
130
  ssl_context = default_ssl_context() if self._ssl_context is None else self._ssl_context
131
- alpn_protocols = ["http/1.1", "h2"] if self._http2 else ["http/1.1"]
131
+ alpn_protocols = (["h2", "http/1.1"] if self._http1 else ["h2"]) if self._http2 else ["http/1.1"]
132
132
  ssl_context.set_alpn_protocols(alpn_protocols)
133
133
 
134
134
  kwargs = {
@@ -105,13 +105,23 @@ class HTTP2Connection(ConnectionInterface):
105
105
  # its max_concurrent_streams value
106
106
  self._max_streams = 1
107
107
 
108
+ # Revoked permits still held by active or queued requests.
109
+ self._max_streams_deficit = 0
110
+
108
111
  local_settings_max_streams = self._h2_state.local_settings.max_concurrent_streams
109
112
  self._max_streams_semaphore = Semaphore(local_settings_max_streams)
110
113
 
111
114
  for _ in range(local_settings_max_streams - self._max_streams):
112
115
  self._max_streams_semaphore.acquire()
113
116
 
114
- self._max_streams_semaphore.acquire()
117
+ # A queued request may receive a permit just before the limit drops.
118
+ while True:
119
+ self._max_streams_semaphore.acquire()
120
+ with ShieldCancellation():
121
+ with self._state_lock:
122
+ if not self._max_streams_deficit:
123
+ break
124
+ self._max_streams_deficit -= 1
115
125
 
116
126
  try:
117
127
  stream_id = self._h2_state.get_next_available_stream_id()
@@ -338,7 +348,6 @@ class HTTP2Connection(ConnectionInterface):
338
348
  for event in events:
339
349
  if isinstance(event, h2.events.RemoteSettingsChanged):
340
350
  with Trace("receive_remote_settings", logger, request) as trace:
341
- self._receive_remote_settings_change(event)
342
351
  trace.return_value = event
343
352
 
344
353
  elif isinstance(
@@ -366,17 +375,25 @@ class HTTP2Connection(ConnectionInterface):
366
375
  self._h2_state.local_settings.max_concurrent_streams,
367
376
  )
368
377
  if new_max_streams and new_max_streams != self._max_streams:
378
+ # Never wait for permits while holding the read lock.
369
379
  while new_max_streams > self._max_streams:
370
- self._max_streams_semaphore.release()
380
+ if self._max_streams_deficit > 0:
381
+ self._max_streams_deficit -= 1
382
+ else:
383
+ self._max_streams_semaphore.release()
371
384
  self._max_streams += 1
372
385
  while new_max_streams < self._max_streams:
373
- self._max_streams_semaphore.acquire()
386
+ if not self._max_streams_semaphore.acquire_if_available():
387
+ self._max_streams_deficit += 1
374
388
  self._max_streams -= 1
375
389
 
376
390
  def _response_closed(self, stream_id: int) -> None:
377
391
  with self._state_lock:
378
392
  if stream_id in self._events:
379
- self._max_streams_semaphore.release()
393
+ if self._max_streams_deficit > 0:
394
+ self._max_streams_deficit -= 1
395
+ else:
396
+ self._max_streams_semaphore.release()
380
397
  del self._events[stream_id]
381
398
  if self._connection_terminated and not self._events:
382
399
  self.close()
@@ -422,7 +439,13 @@ class HTTP2Connection(ConnectionInterface):
422
439
  self._connection_error = True
423
440
  raise exc
424
441
 
425
- events: list[h2.events.Event] = self._h2_state.receive_data(data)
442
+ # Apply settings and stream admission limits atomically.
443
+ with ShieldCancellation():
444
+ with self._state_lock:
445
+ events: list[h2.events.Event] = self._h2_state.receive_data(data)
446
+ for event in events:
447
+ if isinstance(event, h2.events.RemoteSettingsChanged):
448
+ self._receive_remote_settings_change(event)
426
449
 
427
450
  return events
428
451
 
@@ -184,14 +184,16 @@ class ForwardHTTPConnection(ConnectionInterface):
184
184
  scheme=self._proxy_origin.scheme,
185
185
  host=self._proxy_origin.host,
186
186
  port=self._proxy_origin.port,
187
- target=bytes(request.url),
187
+ target=bytes(request.url) if request.url.target.startswith(b"/") else request.url.target,
188
188
  )
189
189
  proxy_request = Request(
190
190
  method=request.method,
191
191
  url=url,
192
192
  headers=headers,
193
193
  content=request.stream,
194
- extensions=request.extensions,
194
+ extensions={
195
+ key: value for key, value in request.extensions.items() if key not in ("sni_hostname", "target")
196
+ },
195
197
  )
196
198
  return self._connection.handle_request(proxy_request)
197
199
 
@@ -274,7 +276,9 @@ class TunnelHTTPConnection(ConnectionInterface):
274
276
  method=b"CONNECT",
275
277
  url=connect_url,
276
278
  headers=connect_headers,
277
- extensions=request.extensions,
279
+ extensions={
280
+ key: value for key, value in request.extensions.items() if key not in ("sni_hostname", "target")
281
+ },
278
282
  )
279
283
  connect_response = self._connection.handle_request(connect_request)
280
284
 
@@ -289,12 +293,13 @@ class TunnelHTTPConnection(ConnectionInterface):
289
293
 
290
294
  # Upgrade the stream to SSL
291
295
  ssl_context = default_ssl_context() if self._ssl_context is None else self._ssl_context
292
- alpn_protocols = ["http/1.1", "h2"] if self._http2 else ["http/1.1"]
296
+ alpn_protocols = (["h2", "http/1.1"] if self._http1 else ["h2"]) if self._http2 else ["http/1.1"]
293
297
  ssl_context.set_alpn_protocols(alpn_protocols)
294
298
 
299
+ server_hostname = request.extensions.get("sni_hostname") or self._remote_origin.host.decode("ascii")
295
300
  kwargs = {
296
301
  "ssl_context": ssl_context,
297
- "server_hostname": self._remote_origin.host.decode("ascii"),
302
+ "server_hostname": server_hostname,
298
303
  "timeout": timeout,
299
304
  }
300
305
  with Trace("start_tls", logger, request, kwargs) as trace:
@@ -242,7 +242,9 @@ class Socks5Connection(ConnectionInterface):
242
242
  # Upgrade the stream to SSL
243
243
  if self._remote_origin.scheme in (b"https", b"wss"):
244
244
  ssl_context = default_ssl_context() if self._ssl_context is None else self._ssl_context
245
- alpn_protocols = ["http/1.1", "h2"] if self._http2 else ["http/1.1"]
245
+ alpn_protocols = (
246
+ (["h2", "http/1.1"] if self._http1 else ["h2"]) if self._http2 else ["http/1.1"]
247
+ )
246
248
  ssl_context.set_alpn_protocols(alpn_protocols)
247
249
 
248
250
  kwargs = {
@@ -175,6 +175,28 @@ class AsyncSemaphore:
175
175
  elif self._backend == "asyncio":
176
176
  await self._anyio_semaphore.acquire()
177
177
 
178
+ def acquire_if_available(self) -> bool:
179
+ """
180
+ Acquire a permit if one is immediately available, without blocking.
181
+ Returns True if a permit was acquired.
182
+
183
+ Like `release()`, this requires `setup()` to have run, which any
184
+ prior `acquire()` call ensures.
185
+ """
186
+ if self._backend == "trio":
187
+ try:
188
+ self._trio_semaphore.acquire_nowait()
189
+ except trio.WouldBlock:
190
+ return False
191
+ return True
192
+ elif self._backend == "asyncio":
193
+ try:
194
+ self._anyio_semaphore.acquire_nowait()
195
+ except anyio.WouldBlock:
196
+ return False
197
+ return True
198
+ return False # pragma: no cover
199
+
178
200
  async def release(self) -> None:
179
201
  if self._backend == "trio":
180
202
  self._trio_semaphore.release()
@@ -293,6 +315,9 @@ class Semaphore:
293
315
  def acquire(self) -> None:
294
316
  self._semaphore.acquire()
295
317
 
318
+ def acquire_if_available(self) -> bool:
319
+ return self._semaphore.acquire(blocking=False)
320
+
296
321
  def release(self) -> None:
297
322
  self._semaphore.release()
298
323
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes