HTTP/2 becomes fully optional (#1140)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* HTTP/2 becomes fully optional * Fix linting, coverage
authored by Tom Christie · committed by GitHub · parent 360b63d · Browse files · 8 files·+47 added−8 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+47 added−8 removed
- tests:+2 added−2 removed
- other:+45 added−6 removed
Provenance
- Commit
8d9dfb5- Tree
0451292- Author
Tom Christie <tom@tomchristie.com>- Committer
GitHub <noreply@github.com>- Parent
360b63d
8 files changed+47 added−8 removed
modified:docs/http2.md+9 added-3 removed
22 unmodified lines232425262728272829303132333435363738396 unmodified lines4647484944505152535414 unmodified lines22 unmodified linesimplementation may be considered the more robust option at this point in time.It is possible that a future version of `httpx` may enable HTTP/2 support by default.
If you're issuing highly concurrent requests you might want to considertrying out our HTTP/2 support. You can do so by instantiating a client withHTTP/2 support enabled:trying out our HTTP/2 support. You can do so by first making sure to installthe optional HTTP/2 dependencies...
```shell$ pip install httpx[http2]```
And then then instantiating a client with HTTP/2 support enabled:
```pythonclient = httpx.AsyncClient(http2=True)...```6 unmodified linesasync with httpx.AsyncClient(http2=True) as client: ...```
HTTP/2 support is available on both `Client`, and `AsyncClient`, although it'sHTTP/2 support is available on both `Client` and `AsyncClient`, although it'stypically more useful in async contexts if you're issuing lots of concurrentrequests.
## Inspecting the HTTP version14 unmodified linesmodified:docs/index.md+6 added
127 unmodified lines128 ```shell129 $ pip install httpx130 ```131 132+Or, to include the optional HTTP/2 support, use:133+134+```shell135+$ pip install httpx[http2]136+```137+138 HTTPX requires Python 3.6+139 140 [sync-support]: https://github.com/encode/httpx/issues/572modified:httpx/_client.py+18 added
475 unmodified lines476 base_url=base_url,477 trust_env=trust_env,478 )479 480+ if http2:481+ try:482+ import h2 # noqa483+ except ImportError: # pragma: nocover484+ raise ImportError(485+ "Using http2=True, but the 'h2' package is not installed. "486+ "Make sure to install httpx using `pip install httpx[http2]`."487+ ) from None488+489 if pool_limits is not None:490 warn_deprecated(491 "Client(..., pool_limits=...) is deprecated and will raise "492 "errors in the future. Use Client(..., limits=...) instead."516 unmodified lines1009 base_url=base_url,1010 trust_env=trust_env,1011 )1012 1013+ if http2:1014+ try:1015+ import h2 # noqa1016+ except ImportError: # pragma: nocover1017+ raise ImportError(1018+ "Using http2=True, but the 'h2' package is not installed. "1019+ "Make sure to install httpx using `pip install httpx[http2]`."1020+ ) from None1021+1022 if pool_limits is not None:1023 warn_deprecated(1024 "AsyncClient(..., pool_limits=...) is deprecated and will raise "1025 "errors in the future. Use AsyncClient(..., limits=...) instead."504 unmodified linesmodified:tests/client/test_async_client.py+1 added-1 removed
6 unmodified lines7 8 @pytest.mark.usefixtures("async_environment")9 async def test_get(server):10 url = server.url11- async with httpx.AsyncClient() as client:11+ async with httpx.AsyncClient(http2=True) as client:12 response = await client.get(url)13 assert response.status_code == 20014 assert response.text == "Hello, world!"15 assert response.http_version == "HTTP/1.1"153 unmodified linesmodified:tests/client/test_client.py+1 added-1 removed
5 unmodified lines6 7 8 def test_get(server):9 url = server.url10- with httpx.Client() as http:10+ with httpx.Client(http2=True) as http:11 response = http.get(url)12 assert response.status_code == 20013 assert response.url == url14 assert response.content == b"Hello, world!"196 unmodified linesmodified:README.md+7 added-1 removed
84 unmodified lines858687888990919293949596979816 unmodified lines11511611711811311912012112212310 unmodified lines84 unmodified lines```shell$ pip install httpx```
Or, to include the optional HTTP/2 support, use:
```shell$ pip install httpx[http2]```
HTTPX requires Python 3.6+.
## Documentation
16 unmodified linesThe HTTPX project relies on these excellent libraries:
* `httpcore` - The underlying transport implementation for `httpx`. * `h11` - HTTP/1.1 support. * `h2` - HTTP/2 support. * `h2` - HTTP/2 support. *(Optional)** `certifi` - SSL certificates.* `chardet` - Fallback auto-detection for response encoding.* `idna` - Internationalized domain name support.* `rfc3986` - URL parsing & normalization.10 unmodified linesmodified:requirements.txt+1 added-1 removed
1--e .1+-e .[http2]2 3 # Optional4 brotlipy==0.7.*5 29 unmodified linesmodified:setup.py+4 added-1 removed
58 unmodified lines59 "sniffio",60 "chardet==3.*",61 "idna==2.*",62 "rfc3986>=1.3,<2",63- "httpcore[http2]==0.10.*",63+ "httpcore==0.10.*",64 ],65+ extras_require={66+ "http2": "h2==3.*",67+ },68 classifiers=[69 "Development Status :: 4 - Beta",70 "Environment :: Web Environment",71 "Intended Audience :: Developers",12 unmodified lines