httpx2 2.4.0__tar.gz → 2.6.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.
- {httpx2-2.4.0 → httpx2-2.6.0}/CHANGELOG.md +11 -0
- {httpx2-2.4.0 → httpx2-2.6.0}/PKG-INFO +8 -11
- {httpx2-2.4.0 → httpx2-2.6.0}/httpx2/__init__.py +6 -0
- {httpx2-2.4.0 → httpx2-2.6.0}/httpx2/_api.py +108 -2
- {httpx2-2.4.0 → httpx2-2.6.0}/httpx2/_client.py +278 -1
- {httpx2-2.4.0 → httpx2-2.6.0}/httpx2/_config.py +5 -0
- {httpx2-2.4.0 → httpx2-2.6.0}/httpx2/_main.py +2 -2
- {httpx2-2.4.0 → httpx2-2.6.0}/httpx2/_models.py +19 -1
- httpx2-2.6.0/httpx2/_sse.py +158 -0
- {httpx2-2.4.0 → httpx2-2.6.0}/httpx2/_utils.py +5 -1
- httpx2-2.6.0/httpx2/websockets/__init__.py +27 -0
- httpx2-2.6.0/httpx2/websockets/_api.py +1359 -0
- httpx2-2.6.0/httpx2/websockets/_exceptions.py +55 -0
- httpx2-2.6.0/httpx2/websockets/_ping.py +41 -0
- httpx2-2.6.0/httpx2/websockets/_transport.py +219 -0
- {httpx2-2.4.0 → httpx2-2.6.0}/pyproject.toml +4 -1
- {httpx2-2.4.0 → httpx2-2.6.0}/.gitignore +0 -0
- {httpx2-2.4.0 → httpx2-2.6.0}/LICENSE.md +0 -0
- {httpx2-2.4.0 → httpx2-2.6.0}/README.md +0 -0
- {httpx2-2.4.0 → httpx2-2.6.0}/httpx2/__version__.py +0 -0
- {httpx2-2.4.0 → httpx2-2.6.0}/httpx2/_auth.py +0 -0
- {httpx2-2.4.0 → httpx2-2.6.0}/httpx2/_content.py +0 -0
- {httpx2-2.4.0 → httpx2-2.6.0}/httpx2/_decoders.py +0 -0
- {httpx2-2.4.0 → httpx2-2.6.0}/httpx2/_exceptions.py +0 -0
- {httpx2-2.4.0 → httpx2-2.6.0}/httpx2/_multipart.py +0 -0
- {httpx2-2.4.0 → httpx2-2.6.0}/httpx2/_status_codes.py +0 -0
- {httpx2-2.4.0 → httpx2-2.6.0}/httpx2/_transports/__init__.py +0 -0
- {httpx2-2.4.0 → httpx2-2.6.0}/httpx2/_transports/asgi.py +0 -0
- {httpx2-2.4.0 → httpx2-2.6.0}/httpx2/_transports/base.py +0 -0
- {httpx2-2.4.0 → httpx2-2.6.0}/httpx2/_transports/default.py +0 -0
- {httpx2-2.4.0 → httpx2-2.6.0}/httpx2/_transports/mock.py +0 -0
- {httpx2-2.4.0 → httpx2-2.6.0}/httpx2/_transports/wsgi.py +0 -0
- {httpx2-2.4.0 → httpx2-2.6.0}/httpx2/_types.py +0 -0
- {httpx2-2.4.0 → httpx2-2.6.0}/httpx2/_urlparse.py +0 -0
- {httpx2-2.4.0 → httpx2-2.6.0}/httpx2/_urls.py +0 -0
- {httpx2-2.4.0 → httpx2-2.6.0}/httpx2/py.typed +0 -0
|
@@ -4,6 +4,17 @@ 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.5.0 (June 25th, 2026)
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
* Add native server-sent events support via `client.sse()`. ([#1046](https://github.com/pydantic/httpx2/pull/1046))
|
|
12
|
+
* Support `|` and `|=` operators for `Headers`. ([#1047](https://github.com/pydantic/httpx2/pull/1047))
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
* Allow IPv6 CIDR notation in `no_proxy`. ([#967](https://github.com/pydantic/httpx2/pull/967))
|
|
17
|
+
|
|
7
18
|
## 2.4.0 (June 11th, 2026)
|
|
8
19
|
|
|
9
20
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: httpx2
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.6.0
|
|
4
4
|
Summary: The next generation HTTP client.
|
|
5
5
|
Project-URL: Changelog, https://github.com/pydantic/httpx2/blob/main/src/httpx2/CHANGELOG.md
|
|
6
6
|
Project-URL: Homepage, https://github.com/pydantic/httpx2
|
|
@@ -26,7 +26,7 @@ Classifier: Programming Language :: Python :: 3.14
|
|
|
26
26
|
Classifier: Topic :: Internet :: WWW/HTTP
|
|
27
27
|
Requires-Python: >=3.10
|
|
28
28
|
Requires-Dist: anyio
|
|
29
|
-
Requires-Dist: httpcore2==2.
|
|
29
|
+
Requires-Dist: httpcore2==2.6.0
|
|
30
30
|
Requires-Dist: idna>=3.18
|
|
31
31
|
Requires-Dist: truststore>=0.10
|
|
32
32
|
Requires-Dist: typing-extensions>=4.5.0; python_version < '3.13'
|
|
@@ -34,13 +34,15 @@ Provides-Extra: brotli
|
|
|
34
34
|
Requires-Dist: brotli; (platform_python_implementation == 'CPython') and extra == 'brotli'
|
|
35
35
|
Requires-Dist: brotlicffi; (platform_python_implementation != 'CPython') and extra == 'brotli'
|
|
36
36
|
Provides-Extra: cli
|
|
37
|
-
Requires-Dist: click
|
|
37
|
+
Requires-Dist: click>=8.4; extra == 'cli'
|
|
38
38
|
Requires-Dist: pygments==2.*; extra == 'cli'
|
|
39
39
|
Requires-Dist: rich<16,>=10; extra == 'cli'
|
|
40
40
|
Provides-Extra: http2
|
|
41
41
|
Requires-Dist: h2<5,>=3; extra == 'http2'
|
|
42
42
|
Provides-Extra: socks
|
|
43
43
|
Requires-Dist: socksio==1.*; extra == 'socks'
|
|
44
|
+
Provides-Extra: ws
|
|
45
|
+
Requires-Dist: wsproto>=1.2; extra == 'ws'
|
|
44
46
|
Provides-Extra: zstd
|
|
45
47
|
Requires-Dist: zstandard>=0.18.0; (python_version <= '3.13') and extra == 'zstd'
|
|
46
48
|
Description-Content-Type: text/markdown
|
|
@@ -188,17 +190,12 @@ inspiration around the lower-level networking details.
|
|
|
188
190
|
|
|
189
191
|
### Added
|
|
190
192
|
|
|
191
|
-
* Add
|
|
192
|
-
|
|
193
|
-
### Changed
|
|
194
|
-
|
|
195
|
-
* Limit the number of chained `Content-Encoding` decoders to 5. ([#1027](https://github.com/pydantic/httpx2/pull/1027))
|
|
196
|
-
* Allow version 15 of `rich` in the `cli` extra. ([#1015](https://github.com/pydantic/httpx2/pull/1015))
|
|
193
|
+
* Add native server-sent events support via `client.sse()`. ([#1046](https://github.com/pydantic/httpx2/pull/1046))
|
|
194
|
+
* Support `|` and `|=` operators for `Headers`. ([#1047](https://github.com/pydantic/httpx2/pull/1047))
|
|
197
195
|
|
|
198
196
|
### Fixed
|
|
199
197
|
|
|
200
|
-
*
|
|
201
|
-
* Decode IDNA labels in non-leading host positions. ([#1018](https://github.com/pydantic/httpx2/pull/1018))
|
|
198
|
+
* Allow IPv6 CIDR notation in `no_proxy`. ([#967](https://github.com/pydantic/httpx2/pull/967))
|
|
202
199
|
|
|
203
200
|
|
|
204
201
|
---
|
|
@@ -6,6 +6,7 @@ from ._config import *
|
|
|
6
6
|
from ._content import *
|
|
7
7
|
from ._exceptions import *
|
|
8
8
|
from ._models import *
|
|
9
|
+
from ._sse import *
|
|
9
10
|
from ._status_codes import *
|
|
10
11
|
from ._transports import *
|
|
11
12
|
from ._types import *
|
|
@@ -35,6 +36,7 @@ __all__ = [
|
|
|
35
36
|
"DecodingError",
|
|
36
37
|
"delete",
|
|
37
38
|
"DigestAuth",
|
|
39
|
+
"EventSource",
|
|
38
40
|
"FunctionAuth",
|
|
39
41
|
"get",
|
|
40
42
|
"head",
|
|
@@ -56,6 +58,7 @@ __all__ = [
|
|
|
56
58
|
"Proxy",
|
|
57
59
|
"ProxyError",
|
|
58
60
|
"put",
|
|
61
|
+
"query",
|
|
59
62
|
"QueryParams",
|
|
60
63
|
"ReadError",
|
|
61
64
|
"ReadTimeout",
|
|
@@ -66,6 +69,8 @@ __all__ = [
|
|
|
66
69
|
"RequestNotRead",
|
|
67
70
|
"Response",
|
|
68
71
|
"ResponseNotRead",
|
|
72
|
+
"ServerSentEvent",
|
|
73
|
+
"SSEError",
|
|
69
74
|
"stream",
|
|
70
75
|
"StreamClosed",
|
|
71
76
|
"StreamConsumed",
|
|
@@ -78,6 +83,7 @@ __all__ = [
|
|
|
78
83
|
"UnsupportedProtocol",
|
|
79
84
|
"URL",
|
|
80
85
|
"USE_CLIENT_DEFAULT",
|
|
86
|
+
"websocket",
|
|
81
87
|
"WriteError",
|
|
82
88
|
"WriteTimeout",
|
|
83
89
|
"WSGITransport",
|
|
@@ -5,7 +5,13 @@ from collections.abc import Generator
|
|
|
5
5
|
from contextlib import contextmanager
|
|
6
6
|
|
|
7
7
|
from ._client import Client
|
|
8
|
-
from ._config import
|
|
8
|
+
from ._config import (
|
|
9
|
+
DEFAULT_KEEPALIVE_PING_INTERVAL_SECONDS,
|
|
10
|
+
DEFAULT_KEEPALIVE_PING_TIMEOUT_SECONDS,
|
|
11
|
+
DEFAULT_MAX_MESSAGE_SIZE_BYTES,
|
|
12
|
+
DEFAULT_QUEUE_SIZE,
|
|
13
|
+
DEFAULT_TIMEOUT_CONFIG,
|
|
14
|
+
)
|
|
9
15
|
from ._models import Response
|
|
10
16
|
from ._types import (
|
|
11
17
|
AuthTypes,
|
|
@@ -23,6 +29,8 @@ from ._urls import URL
|
|
|
23
29
|
if typing.TYPE_CHECKING:
|
|
24
30
|
import ssl # pragma: no cover
|
|
25
31
|
|
|
32
|
+
from .websockets._api import WebSocketSession
|
|
33
|
+
|
|
26
34
|
|
|
27
35
|
__all__ = [
|
|
28
36
|
"delete",
|
|
@@ -32,8 +40,10 @@ __all__ = [
|
|
|
32
40
|
"patch",
|
|
33
41
|
"post",
|
|
34
42
|
"put",
|
|
43
|
+
"query",
|
|
35
44
|
"request",
|
|
36
45
|
"stream",
|
|
46
|
+
"websocket",
|
|
37
47
|
]
|
|
38
48
|
|
|
39
49
|
|
|
@@ -58,7 +68,8 @@ def request(
|
|
|
58
68
|
"""Sends an HTTP request.
|
|
59
69
|
|
|
60
70
|
Parameters:
|
|
61
|
-
method: HTTP method for the new `Request` object: `GET`, `OPTIONS`, `HEAD`, `POST`, `PUT`, `PATCH`,
|
|
71
|
+
method: HTTP method for the new `Request` object: `GET`, `OPTIONS`, `HEAD`, `POST`, `PUT`, `PATCH`, `DELETE`,
|
|
72
|
+
or `QUERY`.
|
|
62
73
|
url: URL for the new `Request` object.
|
|
63
74
|
params: *(optional)* Query parameters to include in the URL, as a string, dictionary, or sequence of two-tuples.
|
|
64
75
|
content: *(optional)* Binary content to include in the body of the request, as bytes or a byte iterator.
|
|
@@ -424,3 +435,98 @@ def delete(
|
|
|
424
435
|
timeout=timeout,
|
|
425
436
|
trust_env=trust_env,
|
|
426
437
|
)
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
def query(
|
|
441
|
+
url: URL | str,
|
|
442
|
+
*,
|
|
443
|
+
content: RequestContent | None = None,
|
|
444
|
+
data: RequestData | None = None,
|
|
445
|
+
files: RequestFiles | None = None,
|
|
446
|
+
json: typing.Any | None = None,
|
|
447
|
+
params: QueryParamTypes | None = None,
|
|
448
|
+
headers: HeaderTypes | None = None,
|
|
449
|
+
cookies: CookieTypes | None = None,
|
|
450
|
+
auth: AuthTypes | None = None,
|
|
451
|
+
proxy: ProxyTypes | None = None,
|
|
452
|
+
follow_redirects: bool = False,
|
|
453
|
+
verify: ssl.SSLContext | str | bool = True,
|
|
454
|
+
timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,
|
|
455
|
+
trust_env: bool = True,
|
|
456
|
+
) -> Response:
|
|
457
|
+
"""
|
|
458
|
+
Sends a `QUERY` request.
|
|
459
|
+
|
|
460
|
+
**Parameters**: See `httpx2.request`.
|
|
461
|
+
"""
|
|
462
|
+
return request(
|
|
463
|
+
"QUERY",
|
|
464
|
+
url,
|
|
465
|
+
content=content,
|
|
466
|
+
data=data,
|
|
467
|
+
files=files,
|
|
468
|
+
json=json,
|
|
469
|
+
params=params,
|
|
470
|
+
headers=headers,
|
|
471
|
+
cookies=cookies,
|
|
472
|
+
auth=auth,
|
|
473
|
+
proxy=proxy,
|
|
474
|
+
follow_redirects=follow_redirects,
|
|
475
|
+
verify=verify,
|
|
476
|
+
timeout=timeout,
|
|
477
|
+
trust_env=trust_env,
|
|
478
|
+
)
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
@contextmanager
|
|
482
|
+
def websocket(
|
|
483
|
+
url: URL | str,
|
|
484
|
+
*,
|
|
485
|
+
params: QueryParamTypes | None = None,
|
|
486
|
+
headers: HeaderTypes | None = None,
|
|
487
|
+
cookies: CookieTypes | None = None,
|
|
488
|
+
auth: AuthTypes | None = None,
|
|
489
|
+
proxy: ProxyTypes | None = None,
|
|
490
|
+
follow_redirects: bool = False,
|
|
491
|
+
timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,
|
|
492
|
+
verify: ssl.SSLContext | str | bool = True,
|
|
493
|
+
trust_env: bool = True,
|
|
494
|
+
subprotocols: list[str] | None = None,
|
|
495
|
+
max_message_size_bytes: int = DEFAULT_MAX_MESSAGE_SIZE_BYTES,
|
|
496
|
+
queue_size: int = DEFAULT_QUEUE_SIZE,
|
|
497
|
+
keepalive_ping_interval_seconds: float | None = DEFAULT_KEEPALIVE_PING_INTERVAL_SECONDS,
|
|
498
|
+
keepalive_ping_timeout_seconds: float | None = DEFAULT_KEEPALIVE_PING_TIMEOUT_SECONDS,
|
|
499
|
+
) -> Generator[WebSocketSession]:
|
|
500
|
+
"""
|
|
501
|
+
Open a WebSocket session.
|
|
502
|
+
|
|
503
|
+
The session is closed automatically when exiting the context manager.
|
|
504
|
+
|
|
505
|
+
```python
|
|
506
|
+
with httpx2.websocket("ws://localhost:8000/ws") as ws:
|
|
507
|
+
ws.send_text("Hello!")
|
|
508
|
+
message = ws.receive_text()
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
**Parameters**: See `httpx2.request` and `httpx2.Client.websocket`.
|
|
512
|
+
"""
|
|
513
|
+
with Client(
|
|
514
|
+
cookies=cookies,
|
|
515
|
+
proxy=proxy,
|
|
516
|
+
verify=verify,
|
|
517
|
+
timeout=timeout,
|
|
518
|
+
trust_env=trust_env,
|
|
519
|
+
) as client:
|
|
520
|
+
with client.websocket(
|
|
521
|
+
url,
|
|
522
|
+
params=params,
|
|
523
|
+
headers=headers,
|
|
524
|
+
auth=auth,
|
|
525
|
+
follow_redirects=follow_redirects,
|
|
526
|
+
subprotocols=subprotocols,
|
|
527
|
+
max_message_size_bytes=max_message_size_bytes,
|
|
528
|
+
queue_size=queue_size,
|
|
529
|
+
keepalive_ping_interval_seconds=keepalive_ping_interval_seconds,
|
|
530
|
+
keepalive_ping_timeout_seconds=keepalive_ping_timeout_seconds,
|
|
531
|
+
) as session:
|
|
532
|
+
yield session
|
|
@@ -13,8 +13,12 @@ from types import TracebackType
|
|
|
13
13
|
from .__version__ import __version__
|
|
14
14
|
from ._auth import Auth, BasicAuth, FunctionAuth
|
|
15
15
|
from ._config import (
|
|
16
|
+
DEFAULT_KEEPALIVE_PING_INTERVAL_SECONDS,
|
|
17
|
+
DEFAULT_KEEPALIVE_PING_TIMEOUT_SECONDS,
|
|
16
18
|
DEFAULT_LIMITS,
|
|
19
|
+
DEFAULT_MAX_MESSAGE_SIZE_BYTES,
|
|
17
20
|
DEFAULT_MAX_REDIRECTS,
|
|
21
|
+
DEFAULT_QUEUE_SIZE,
|
|
18
22
|
DEFAULT_TIMEOUT_CONFIG,
|
|
19
23
|
Limits,
|
|
20
24
|
Proxy,
|
|
@@ -28,6 +32,7 @@ from ._exceptions import (
|
|
|
28
32
|
request_context,
|
|
29
33
|
)
|
|
30
34
|
from ._models import Cookies, Headers, Request, Response
|
|
35
|
+
from ._sse import EventSource
|
|
31
36
|
from ._status_codes import codes
|
|
32
37
|
from ._transports.base import AsyncBaseTransport, BaseTransport
|
|
33
38
|
from ._transports.default import AsyncHTTPTransport, HTTPTransport
|
|
@@ -52,6 +57,8 @@ from ._utils import URLPattern, get_environment_proxies
|
|
|
52
57
|
if typing.TYPE_CHECKING:
|
|
53
58
|
import ssl # pragma: no cover
|
|
54
59
|
|
|
60
|
+
from .websockets._api import AsyncWebSocketSession, WebSocketSession
|
|
61
|
+
|
|
55
62
|
__all__ = ["USE_CLIENT_DEFAULT", "AsyncClient", "Client"]
|
|
56
63
|
|
|
57
64
|
# The type annotation for @classmethod and context managers here follows PEP 484
|
|
@@ -481,7 +488,9 @@ class BaseClient:
|
|
|
481
488
|
|
|
482
489
|
# Do what the browsers do, despite standards...
|
|
483
490
|
# Turn 302s into GETs.
|
|
484
|
-
|
|
491
|
+
# QUERY is excluded, per RFC 10008 Section 2.5.
|
|
492
|
+
# https://datatracker.ietf.org/doc/html/rfc10008#section-2.5
|
|
493
|
+
if response.status_code == codes.FOUND and method not in ("HEAD", "QUERY"):
|
|
485
494
|
method = "GET"
|
|
486
495
|
|
|
487
496
|
# If a POST is responded to with a 301, turn it into a GET.
|
|
@@ -845,6 +854,103 @@ class Client(BaseClient):
|
|
|
845
854
|
finally:
|
|
846
855
|
response.close()
|
|
847
856
|
|
|
857
|
+
@contextmanager
|
|
858
|
+
def sse(
|
|
859
|
+
self,
|
|
860
|
+
url: URL | str,
|
|
861
|
+
*,
|
|
862
|
+
method: str = "GET",
|
|
863
|
+
content: RequestContent | None = None,
|
|
864
|
+
data: RequestData | None = None,
|
|
865
|
+
files: RequestFiles | None = None,
|
|
866
|
+
json: typing.Any | None = None,
|
|
867
|
+
params: QueryParamTypes | None = None,
|
|
868
|
+
headers: HeaderTypes | None = None,
|
|
869
|
+
cookies: CookieTypes | None = None,
|
|
870
|
+
auth: AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT,
|
|
871
|
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
|
872
|
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
|
873
|
+
extensions: RequestExtensions | None = None,
|
|
874
|
+
) -> Generator[EventSource]:
|
|
875
|
+
"""
|
|
876
|
+
Connect to a server-sent events endpoint and yield an `EventSource`.
|
|
877
|
+
|
|
878
|
+
Iterating the `EventSource` yields `ServerSentEvent` instances.
|
|
879
|
+
|
|
880
|
+
**Parameters**: See `httpx2.request`.
|
|
881
|
+
"""
|
|
882
|
+
with self.stream(
|
|
883
|
+
method,
|
|
884
|
+
url,
|
|
885
|
+
content=content,
|
|
886
|
+
data=data,
|
|
887
|
+
files=files,
|
|
888
|
+
json=json,
|
|
889
|
+
params=params,
|
|
890
|
+
headers={"Accept": "text/event-stream", "Cache-Control": "no-store"} | Headers(headers),
|
|
891
|
+
cookies=cookies,
|
|
892
|
+
auth=auth,
|
|
893
|
+
follow_redirects=follow_redirects,
|
|
894
|
+
timeout=timeout,
|
|
895
|
+
extensions=extensions,
|
|
896
|
+
) as response:
|
|
897
|
+
yield EventSource(response)
|
|
898
|
+
|
|
899
|
+
@contextmanager
|
|
900
|
+
def websocket(
|
|
901
|
+
self,
|
|
902
|
+
url: URL | str,
|
|
903
|
+
*,
|
|
904
|
+
max_message_size_bytes: int = DEFAULT_MAX_MESSAGE_SIZE_BYTES,
|
|
905
|
+
queue_size: int = DEFAULT_QUEUE_SIZE,
|
|
906
|
+
keepalive_ping_interval_seconds: float | None = DEFAULT_KEEPALIVE_PING_INTERVAL_SECONDS,
|
|
907
|
+
keepalive_ping_timeout_seconds: float | None = DEFAULT_KEEPALIVE_PING_TIMEOUT_SECONDS,
|
|
908
|
+
subprotocols: list[str] | None = None,
|
|
909
|
+
params: QueryParamTypes | None = None,
|
|
910
|
+
headers: HeaderTypes | None = None,
|
|
911
|
+
cookies: CookieTypes | None = None,
|
|
912
|
+
auth: AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT,
|
|
913
|
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
|
914
|
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
|
915
|
+
extensions: RequestExtensions | None = None,
|
|
916
|
+
) -> Generator[WebSocketSession]:
|
|
917
|
+
"""
|
|
918
|
+
Open a WebSocket session, using this client's configuration.
|
|
919
|
+
|
|
920
|
+
The session is closed automatically when exiting the context manager.
|
|
921
|
+
|
|
922
|
+
```python
|
|
923
|
+
with httpx2.Client() as client:
|
|
924
|
+
with client.websocket("ws://localhost:8000/ws") as ws:
|
|
925
|
+
ws.send_text("Hello!")
|
|
926
|
+
message = ws.receive_text()
|
|
927
|
+
```
|
|
928
|
+
"""
|
|
929
|
+
try:
|
|
930
|
+
from .websockets._api import connect_ws
|
|
931
|
+
except ImportError: # pragma: no cover
|
|
932
|
+
raise ImportError(
|
|
933
|
+
"WebSocket support requires the `wsproto` package. Install it with `pip install httpx2[ws]`."
|
|
934
|
+
)
|
|
935
|
+
|
|
936
|
+
with connect_ws(
|
|
937
|
+
str(url),
|
|
938
|
+
self,
|
|
939
|
+
max_message_size_bytes=max_message_size_bytes,
|
|
940
|
+
queue_size=queue_size,
|
|
941
|
+
keepalive_ping_interval_seconds=keepalive_ping_interval_seconds,
|
|
942
|
+
keepalive_ping_timeout_seconds=keepalive_ping_timeout_seconds,
|
|
943
|
+
subprotocols=subprotocols,
|
|
944
|
+
params=params,
|
|
945
|
+
headers=headers,
|
|
946
|
+
cookies=cookies,
|
|
947
|
+
auth=auth,
|
|
948
|
+
follow_redirects=follow_redirects,
|
|
949
|
+
timeout=timeout,
|
|
950
|
+
extensions=extensions,
|
|
951
|
+
) as session:
|
|
952
|
+
yield session
|
|
953
|
+
|
|
848
954
|
def send(
|
|
849
955
|
self,
|
|
850
956
|
request: Request,
|
|
@@ -1219,6 +1325,43 @@ class Client(BaseClient):
|
|
|
1219
1325
|
extensions=extensions,
|
|
1220
1326
|
)
|
|
1221
1327
|
|
|
1328
|
+
def query(
|
|
1329
|
+
self,
|
|
1330
|
+
url: URL | str,
|
|
1331
|
+
*,
|
|
1332
|
+
content: RequestContent | None = None,
|
|
1333
|
+
data: RequestData | None = None,
|
|
1334
|
+
files: RequestFiles | None = None,
|
|
1335
|
+
json: typing.Any | None = None,
|
|
1336
|
+
params: QueryParamTypes | None = None,
|
|
1337
|
+
headers: HeaderTypes | None = None,
|
|
1338
|
+
cookies: CookieTypes | None = None,
|
|
1339
|
+
auth: AuthTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
|
1340
|
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
|
1341
|
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
|
1342
|
+
extensions: RequestExtensions | None = None,
|
|
1343
|
+
) -> Response:
|
|
1344
|
+
"""
|
|
1345
|
+
Send a `QUERY` request.
|
|
1346
|
+
|
|
1347
|
+
**Parameters**: See `httpx2.request`.
|
|
1348
|
+
"""
|
|
1349
|
+
return self.request(
|
|
1350
|
+
"QUERY",
|
|
1351
|
+
url,
|
|
1352
|
+
content=content,
|
|
1353
|
+
data=data,
|
|
1354
|
+
files=files,
|
|
1355
|
+
json=json,
|
|
1356
|
+
params=params,
|
|
1357
|
+
headers=headers,
|
|
1358
|
+
cookies=cookies,
|
|
1359
|
+
auth=auth,
|
|
1360
|
+
follow_redirects=follow_redirects,
|
|
1361
|
+
timeout=timeout,
|
|
1362
|
+
extensions=extensions,
|
|
1363
|
+
)
|
|
1364
|
+
|
|
1222
1365
|
def close(self) -> None:
|
|
1223
1366
|
"""
|
|
1224
1367
|
Close transport and proxies.
|
|
@@ -1548,6 +1691,103 @@ class AsyncClient(BaseClient):
|
|
|
1548
1691
|
finally:
|
|
1549
1692
|
await response.aclose()
|
|
1550
1693
|
|
|
1694
|
+
@asynccontextmanager
|
|
1695
|
+
async def sse(
|
|
1696
|
+
self,
|
|
1697
|
+
url: URL | str,
|
|
1698
|
+
*,
|
|
1699
|
+
method: str = "GET",
|
|
1700
|
+
content: RequestContent | None = None,
|
|
1701
|
+
data: RequestData | None = None,
|
|
1702
|
+
files: RequestFiles | None = None,
|
|
1703
|
+
json: typing.Any | None = None,
|
|
1704
|
+
params: QueryParamTypes | None = None,
|
|
1705
|
+
headers: HeaderTypes | None = None,
|
|
1706
|
+
cookies: CookieTypes | None = None,
|
|
1707
|
+
auth: AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT,
|
|
1708
|
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
|
1709
|
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
|
1710
|
+
extensions: RequestExtensions | None = None,
|
|
1711
|
+
) -> AsyncGenerator[EventSource]:
|
|
1712
|
+
"""
|
|
1713
|
+
Connect to a server-sent events endpoint and yield an `EventSource`.
|
|
1714
|
+
|
|
1715
|
+
Iterating the `EventSource` yields `ServerSentEvent` instances.
|
|
1716
|
+
|
|
1717
|
+
**Parameters**: See `httpx2.request`.
|
|
1718
|
+
"""
|
|
1719
|
+
async with self.stream(
|
|
1720
|
+
method,
|
|
1721
|
+
url,
|
|
1722
|
+
content=content,
|
|
1723
|
+
data=data,
|
|
1724
|
+
files=files,
|
|
1725
|
+
json=json,
|
|
1726
|
+
params=params,
|
|
1727
|
+
headers={"Accept": "text/event-stream", "Cache-Control": "no-store"} | Headers(headers),
|
|
1728
|
+
cookies=cookies,
|
|
1729
|
+
auth=auth,
|
|
1730
|
+
follow_redirects=follow_redirects,
|
|
1731
|
+
timeout=timeout,
|
|
1732
|
+
extensions=extensions,
|
|
1733
|
+
) as response:
|
|
1734
|
+
yield EventSource(response)
|
|
1735
|
+
|
|
1736
|
+
@asynccontextmanager
|
|
1737
|
+
async def websocket(
|
|
1738
|
+
self,
|
|
1739
|
+
url: URL | str,
|
|
1740
|
+
*,
|
|
1741
|
+
max_message_size_bytes: int = DEFAULT_MAX_MESSAGE_SIZE_BYTES,
|
|
1742
|
+
queue_size: int = DEFAULT_QUEUE_SIZE,
|
|
1743
|
+
keepalive_ping_interval_seconds: float | None = DEFAULT_KEEPALIVE_PING_INTERVAL_SECONDS,
|
|
1744
|
+
keepalive_ping_timeout_seconds: float | None = DEFAULT_KEEPALIVE_PING_TIMEOUT_SECONDS,
|
|
1745
|
+
subprotocols: list[str] | None = None,
|
|
1746
|
+
params: QueryParamTypes | None = None,
|
|
1747
|
+
headers: HeaderTypes | None = None,
|
|
1748
|
+
cookies: CookieTypes | None = None,
|
|
1749
|
+
auth: AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT,
|
|
1750
|
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
|
1751
|
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
|
1752
|
+
extensions: RequestExtensions | None = None,
|
|
1753
|
+
) -> AsyncGenerator[AsyncWebSocketSession]:
|
|
1754
|
+
"""
|
|
1755
|
+
Open a WebSocket session, using this client's configuration.
|
|
1756
|
+
|
|
1757
|
+
The session is closed automatically when exiting the context manager.
|
|
1758
|
+
|
|
1759
|
+
```python
|
|
1760
|
+
async with httpx2.AsyncClient() as client:
|
|
1761
|
+
async with client.websocket("ws://localhost:8000/ws") as ws:
|
|
1762
|
+
await ws.send_text("Hello!")
|
|
1763
|
+
message = await ws.receive_text()
|
|
1764
|
+
```
|
|
1765
|
+
"""
|
|
1766
|
+
try:
|
|
1767
|
+
from .websockets._api import aconnect_ws
|
|
1768
|
+
except ImportError: # pragma: no cover
|
|
1769
|
+
raise ImportError(
|
|
1770
|
+
"WebSocket support requires the `wsproto` package. Install it with `pip install httpx2[ws]`."
|
|
1771
|
+
)
|
|
1772
|
+
|
|
1773
|
+
async with aconnect_ws(
|
|
1774
|
+
str(url),
|
|
1775
|
+
self,
|
|
1776
|
+
max_message_size_bytes=max_message_size_bytes,
|
|
1777
|
+
queue_size=queue_size,
|
|
1778
|
+
keepalive_ping_interval_seconds=keepalive_ping_interval_seconds,
|
|
1779
|
+
keepalive_ping_timeout_seconds=keepalive_ping_timeout_seconds,
|
|
1780
|
+
subprotocols=subprotocols,
|
|
1781
|
+
params=params,
|
|
1782
|
+
headers=headers,
|
|
1783
|
+
cookies=cookies,
|
|
1784
|
+
auth=auth,
|
|
1785
|
+
follow_redirects=follow_redirects,
|
|
1786
|
+
timeout=timeout,
|
|
1787
|
+
extensions=extensions,
|
|
1788
|
+
) as session:
|
|
1789
|
+
yield session
|
|
1790
|
+
|
|
1551
1791
|
async def send(
|
|
1552
1792
|
self,
|
|
1553
1793
|
request: Request,
|
|
@@ -1922,6 +2162,43 @@ class AsyncClient(BaseClient):
|
|
|
1922
2162
|
extensions=extensions,
|
|
1923
2163
|
)
|
|
1924
2164
|
|
|
2165
|
+
async def query(
|
|
2166
|
+
self,
|
|
2167
|
+
url: URL | str,
|
|
2168
|
+
*,
|
|
2169
|
+
content: RequestContent | None = None,
|
|
2170
|
+
data: RequestData | None = None,
|
|
2171
|
+
files: RequestFiles | None = None,
|
|
2172
|
+
json: typing.Any | None = None,
|
|
2173
|
+
params: QueryParamTypes | None = None,
|
|
2174
|
+
headers: HeaderTypes | None = None,
|
|
2175
|
+
cookies: CookieTypes | None = None,
|
|
2176
|
+
auth: AuthTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
|
2177
|
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
|
2178
|
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
|
2179
|
+
extensions: RequestExtensions | None = None,
|
|
2180
|
+
) -> Response:
|
|
2181
|
+
"""
|
|
2182
|
+
Send a `QUERY` request.
|
|
2183
|
+
|
|
2184
|
+
**Parameters**: See `httpx2.request`.
|
|
2185
|
+
"""
|
|
2186
|
+
return await self.request(
|
|
2187
|
+
"QUERY",
|
|
2188
|
+
url,
|
|
2189
|
+
content=content,
|
|
2190
|
+
data=data,
|
|
2191
|
+
files=files,
|
|
2192
|
+
json=json,
|
|
2193
|
+
params=params,
|
|
2194
|
+
headers=headers,
|
|
2195
|
+
cookies=cookies,
|
|
2196
|
+
auth=auth,
|
|
2197
|
+
follow_redirects=follow_redirects,
|
|
2198
|
+
timeout=timeout,
|
|
2199
|
+
extensions=extensions,
|
|
2200
|
+
)
|
|
2201
|
+
|
|
1925
2202
|
async def aclose(self) -> None:
|
|
1926
2203
|
"""
|
|
1927
2204
|
Close transport and proxies.
|
|
@@ -247,3 +247,8 @@ class Proxy:
|
|
|
247
247
|
DEFAULT_TIMEOUT_CONFIG = Timeout(timeout=5.0)
|
|
248
248
|
DEFAULT_LIMITS = Limits(max_connections=100, max_keepalive_connections=20)
|
|
249
249
|
DEFAULT_MAX_REDIRECTS = 20
|
|
250
|
+
|
|
251
|
+
DEFAULT_MAX_MESSAGE_SIZE_BYTES = 65_536
|
|
252
|
+
DEFAULT_QUEUE_SIZE = 512
|
|
253
|
+
DEFAULT_KEEPALIVE_PING_INTERVAL_SECONDS = 20.0
|
|
254
|
+
DEFAULT_KEEPALIVE_PING_TIMEOUT_SECONDS = 20.0
|
|
@@ -38,7 +38,7 @@ def print_help() -> None:
|
|
|
38
38
|
table.add_column("Description")
|
|
39
39
|
table.add_row(
|
|
40
40
|
"-m, --method [cyan]METHOD",
|
|
41
|
-
"Request method, such as GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD.\n"
|
|
41
|
+
"Request method, such as GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD, QUERY.\n"
|
|
42
42
|
"[Default: GET, or POST if a request body is included]",
|
|
43
43
|
)
|
|
44
44
|
table.add_row(
|
|
@@ -297,7 +297,7 @@ def handle_help(
|
|
|
297
297
|
"method",
|
|
298
298
|
type=str,
|
|
299
299
|
help=(
|
|
300
|
-
"Request method, such as GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD. "
|
|
300
|
+
"Request method, such as GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD, QUERY. "
|
|
301
301
|
"[Default: GET, or POST if a request body is included]"
|
|
302
302
|
),
|
|
303
303
|
)
|
|
@@ -277,6 +277,24 @@ class Headers(typing.MutableMapping[str, str]):
|
|
|
277
277
|
def copy(self) -> Headers:
|
|
278
278
|
return Headers(self, encoding=self.encoding)
|
|
279
279
|
|
|
280
|
+
def __or__(self, other: Mapping[str, str]) -> Headers:
|
|
281
|
+
if not isinstance(other, Mapping):
|
|
282
|
+
return NotImplemented
|
|
283
|
+
merged = self.copy()
|
|
284
|
+
merged.update(other)
|
|
285
|
+
return merged
|
|
286
|
+
|
|
287
|
+
def __ror__(self, other: Mapping[str, str]) -> Headers:
|
|
288
|
+
if not isinstance(other, Mapping):
|
|
289
|
+
return NotImplemented
|
|
290
|
+
merged = Headers(other)
|
|
291
|
+
merged.update(self)
|
|
292
|
+
return merged
|
|
293
|
+
|
|
294
|
+
def __ior__(self, other: HeaderTypes) -> Headers:
|
|
295
|
+
self.update(other)
|
|
296
|
+
return self
|
|
297
|
+
|
|
280
298
|
def __getitem__(self, key: str) -> str:
|
|
281
299
|
"""
|
|
282
300
|
Return a single header value.
|
|
@@ -438,7 +456,7 @@ class Request:
|
|
|
438
456
|
|
|
439
457
|
if not has_host and self.url.host:
|
|
440
458
|
auto_headers.append((b"Host", self.url.netloc))
|
|
441
|
-
if not has_content_length and self.method in ("POST", "PUT", "PATCH"):
|
|
459
|
+
if not has_content_length and self.method in ("POST", "PUT", "PATCH", "QUERY"):
|
|
442
460
|
auto_headers.append((b"Content-Length", b"0"))
|
|
443
461
|
|
|
444
462
|
self.headers = Headers(auto_headers + self.headers.raw)
|