httpx2 2.5.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.5.0 → httpx2-2.6.0}/PKG-INFO +5 -3
- {httpx2-2.5.0 → httpx2-2.6.0}/httpx2/__init__.py +2 -0
- {httpx2-2.5.0 → httpx2-2.6.0}/httpx2/_api.py +108 -2
- {httpx2-2.5.0 → httpx2-2.6.0}/httpx2/_client.py +193 -1
- {httpx2-2.5.0 → httpx2-2.6.0}/httpx2/_config.py +5 -0
- {httpx2-2.5.0 → httpx2-2.6.0}/httpx2/_main.py +2 -2
- {httpx2-2.5.0 → httpx2-2.6.0}/httpx2/_models.py +1 -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.5.0 → httpx2-2.6.0}/pyproject.toml +4 -1
- {httpx2-2.5.0 → httpx2-2.6.0}/.gitignore +0 -0
- {httpx2-2.5.0 → httpx2-2.6.0}/CHANGELOG.md +0 -0
- {httpx2-2.5.0 → httpx2-2.6.0}/LICENSE.md +0 -0
- {httpx2-2.5.0 → httpx2-2.6.0}/README.md +0 -0
- {httpx2-2.5.0 → httpx2-2.6.0}/httpx2/__version__.py +0 -0
- {httpx2-2.5.0 → httpx2-2.6.0}/httpx2/_auth.py +0 -0
- {httpx2-2.5.0 → httpx2-2.6.0}/httpx2/_content.py +0 -0
- {httpx2-2.5.0 → httpx2-2.6.0}/httpx2/_decoders.py +0 -0
- {httpx2-2.5.0 → httpx2-2.6.0}/httpx2/_exceptions.py +0 -0
- {httpx2-2.5.0 → httpx2-2.6.0}/httpx2/_multipart.py +0 -0
- {httpx2-2.5.0 → httpx2-2.6.0}/httpx2/_sse.py +0 -0
- {httpx2-2.5.0 → httpx2-2.6.0}/httpx2/_status_codes.py +0 -0
- {httpx2-2.5.0 → httpx2-2.6.0}/httpx2/_transports/__init__.py +0 -0
- {httpx2-2.5.0 → httpx2-2.6.0}/httpx2/_transports/asgi.py +0 -0
- {httpx2-2.5.0 → httpx2-2.6.0}/httpx2/_transports/base.py +0 -0
- {httpx2-2.5.0 → httpx2-2.6.0}/httpx2/_transports/default.py +0 -0
- {httpx2-2.5.0 → httpx2-2.6.0}/httpx2/_transports/mock.py +0 -0
- {httpx2-2.5.0 → httpx2-2.6.0}/httpx2/_transports/wsgi.py +0 -0
- {httpx2-2.5.0 → httpx2-2.6.0}/httpx2/_types.py +0 -0
- {httpx2-2.5.0 → httpx2-2.6.0}/httpx2/_urlparse.py +0 -0
- {httpx2-2.5.0 → httpx2-2.6.0}/httpx2/_urls.py +0 -0
- {httpx2-2.5.0 → httpx2-2.6.0}/httpx2/_utils.py +0 -0
- {httpx2-2.5.0 → httpx2-2.6.0}/httpx2/py.typed +0 -0
|
@@ -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
|
|
@@ -58,6 +58,7 @@ __all__ = [
|
|
|
58
58
|
"Proxy",
|
|
59
59
|
"ProxyError",
|
|
60
60
|
"put",
|
|
61
|
+
"query",
|
|
61
62
|
"QueryParams",
|
|
62
63
|
"ReadError",
|
|
63
64
|
"ReadTimeout",
|
|
@@ -82,6 +83,7 @@ __all__ = [
|
|
|
82
83
|
"UnsupportedProtocol",
|
|
83
84
|
"URL",
|
|
84
85
|
"USE_CLIENT_DEFAULT",
|
|
86
|
+
"websocket",
|
|
85
87
|
"WriteError",
|
|
86
88
|
"WriteTimeout",
|
|
87
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,
|
|
@@ -53,6 +57,8 @@ from ._utils import URLPattern, get_environment_proxies
|
|
|
53
57
|
if typing.TYPE_CHECKING:
|
|
54
58
|
import ssl # pragma: no cover
|
|
55
59
|
|
|
60
|
+
from .websockets._api import AsyncWebSocketSession, WebSocketSession
|
|
61
|
+
|
|
56
62
|
__all__ = ["USE_CLIENT_DEFAULT", "AsyncClient", "Client"]
|
|
57
63
|
|
|
58
64
|
# The type annotation for @classmethod and context managers here follows PEP 484
|
|
@@ -482,7 +488,9 @@ class BaseClient:
|
|
|
482
488
|
|
|
483
489
|
# Do what the browsers do, despite standards...
|
|
484
490
|
# Turn 302s into GETs.
|
|
485
|
-
|
|
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"):
|
|
486
494
|
method = "GET"
|
|
487
495
|
|
|
488
496
|
# If a POST is responded to with a 301, turn it into a GET.
|
|
@@ -888,6 +896,61 @@ class Client(BaseClient):
|
|
|
888
896
|
) as response:
|
|
889
897
|
yield EventSource(response)
|
|
890
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
|
+
|
|
891
954
|
def send(
|
|
892
955
|
self,
|
|
893
956
|
request: Request,
|
|
@@ -1262,6 +1325,43 @@ class Client(BaseClient):
|
|
|
1262
1325
|
extensions=extensions,
|
|
1263
1326
|
)
|
|
1264
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
|
+
|
|
1265
1365
|
def close(self) -> None:
|
|
1266
1366
|
"""
|
|
1267
1367
|
Close transport and proxies.
|
|
@@ -1633,6 +1733,61 @@ class AsyncClient(BaseClient):
|
|
|
1633
1733
|
) as response:
|
|
1634
1734
|
yield EventSource(response)
|
|
1635
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
|
+
|
|
1636
1791
|
async def send(
|
|
1637
1792
|
self,
|
|
1638
1793
|
request: Request,
|
|
@@ -2007,6 +2162,43 @@ class AsyncClient(BaseClient):
|
|
|
2007
2162
|
extensions=extensions,
|
|
2008
2163
|
)
|
|
2009
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
|
+
|
|
2010
2202
|
async def aclose(self) -> None:
|
|
2011
2203
|
"""
|
|
2012
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
|
)
|
|
@@ -456,7 +456,7 @@ class Request:
|
|
|
456
456
|
|
|
457
457
|
if not has_host and self.url.host:
|
|
458
458
|
auto_headers.append((b"Host", self.url.netloc))
|
|
459
|
-
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"):
|
|
460
460
|
auto_headers.append((b"Content-Length", b"0"))
|
|
461
461
|
|
|
462
462
|
self.headers = Headers(auto_headers + self.headers.raw)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""
|
|
2
|
+
WebSocket support, derived from httpx-ws (https://github.com/frankie567/httpx-ws).
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2021 François Voron, MIT License (https://github.com/frankie567/httpx-ws/blob/main/LICENSE).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from ._api import AsyncWebSocketSession, JSONMode, WebSocketSession
|
|
8
|
+
from ._exceptions import (
|
|
9
|
+
HTTPXWSException,
|
|
10
|
+
WebSocketDisconnect,
|
|
11
|
+
WebSocketInvalidTypeReceived,
|
|
12
|
+
WebSocketNetworkError,
|
|
13
|
+
WebSocketUpgradeError,
|
|
14
|
+
)
|
|
15
|
+
from ._transport import ASGIWebSocketTransport
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"ASGIWebSocketTransport",
|
|
19
|
+
"AsyncWebSocketSession",
|
|
20
|
+
"HTTPXWSException",
|
|
21
|
+
"JSONMode",
|
|
22
|
+
"WebSocketDisconnect",
|
|
23
|
+
"WebSocketInvalidTypeReceived",
|
|
24
|
+
"WebSocketNetworkError",
|
|
25
|
+
"WebSocketSession",
|
|
26
|
+
"WebSocketUpgradeError",
|
|
27
|
+
]
|