]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
HTTP/2 becomes fully optional (#1140)
authorTom Christie <tom@tomchristie.com>
Fri, 7 Aug 2020 14:16:21 +0000 (15:16 +0100)
committerGitHub <noreply@github.com>
Fri, 7 Aug 2020 14:16:21 +0000 (15:16 +0100)
* HTTP/2 becomes fully optional

* Fix linting, coverage

README.md
docs/http2.md
docs/index.md
httpx/_client.py
requirements.txt
setup.py
tests/client/test_async_client.py
tests/client/test_client.py

index 9ce2311ed8c118dd5f528665bd456b2d75ccc29e..b84214d5cdca37ce0e39c8ce1bbc5ce2c33f93ca 100644 (file)
--- a/README.md
+++ b/README.md
@@ -86,6 +86,12 @@ Install with pip:
 $ pip install httpx
 ```
 
+Or, to include the optional HTTP/2 support, use:
+
+```shell
+$ pip install httpx[http2]
+```
+
 HTTPX requires Python 3.6+.
 
 ## Documentation
@@ -110,7 +116,7 @@ The 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.
index 45a08cdec0f2d55e7a3f6d38bba804f720061826..84148c3b3337979db5f344f871b5f2b28fa18270 100644 (file)
@@ -24,8 +24,14 @@ implementation 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 consider
-trying out our HTTP/2 support. You can do so by instantiating a client with
-HTTP/2 support enabled:
+trying out our HTTP/2 support. You can do so by first making sure to install
+the optional HTTP/2 dependencies...
+
+```shell
+$ pip install httpx[http2]
+```
+
+And then then instantiating a client with HTTP/2 support enabled:
 
 ```python
 client = httpx.AsyncClient(http2=True)
@@ -41,7 +47,7 @@ async with httpx.AsyncClient(http2=True) as client:
     ...
 ```
 
-HTTP/2 support is available on both `Client`, and `AsyncClient`, although it's
+HTTP/2 support is available on both `Client` and `AsyncClient`, although it's
 typically more useful in async contexts if you're issuing lots of concurrent
 requests.
 
index 1241069133757d86cae02635549f18a6347d4211..38721f89a1627e1cd1ae61f450247d2560ef7679 100644 (file)
@@ -129,6 +129,12 @@ Install with pip:
 $ pip install httpx
 ```
 
+Or, to include the optional HTTP/2 support, use:
+
+```shell
+$ pip install httpx[http2]
+```
+
 HTTPX requires Python 3.6+
 
 [sync-support]: https://github.com/encode/httpx/issues/572
index d319ed81ac9faba1fa6fbf9006d59f177dceb338..a9fd495c91082796a33cf86dfa31bcd40a6f268c 100644 (file)
@@ -477,6 +477,15 @@ class Client(BaseClient):
             trust_env=trust_env,
         )
 
+        if http2:
+            try:
+                import h2  # noqa
+            except ImportError:  # pragma: nocover
+                raise ImportError(
+                    "Using http2=True, but the 'h2' package is not installed. "
+                    "Make sure to install httpx using `pip install httpx[http2]`."
+                ) from None
+
         if pool_limits is not None:
             warn_deprecated(
                 "Client(..., pool_limits=...) is deprecated and will raise "
@@ -1001,6 +1010,15 @@ class AsyncClient(BaseClient):
             trust_env=trust_env,
         )
 
+        if http2:
+            try:
+                import h2  # noqa
+            except ImportError:  # pragma: nocover
+                raise ImportError(
+                    "Using http2=True, but the 'h2' package is not installed. "
+                    "Make sure to install httpx using `pip install httpx[http2]`."
+                ) from None
+
         if pool_limits is not None:
             warn_deprecated(
                 "AsyncClient(..., pool_limits=...) is deprecated and will raise "
index cc05742a8ba442f4b8487704cb6f3e80d3507fd3..a901dbeaa8e6bdb3e05252ccf967cbba0481f90b 100644 (file)
@@ -1,4 +1,4 @@
--e .
+-e .[http2]
 
 # Optional
 brotlipy==0.7.*
index d8b545c5a32998a0afa5fda522dc850538d3d547..1b449a40c9f07a96d873c0cd56b731a005b5e384 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -60,8 +60,11 @@ setup(
         "chardet==3.*",
         "idna==2.*",
         "rfc3986>=1.3,<2",
-        "httpcore[http2]==0.10.*",
+        "httpcore==0.10.*",
     ],
+    extras_require={
+        "http2": "h2==3.*",
+    },
     classifiers=[
         "Development Status :: 4 - Beta",
         "Environment :: Web Environment",
index ae3a0c07cf5de8cee128c9cc66c52370cfecc37c..78669e2860bf9de984c174482df15c671d439deb 100644 (file)
@@ -8,7 +8,7 @@ import httpx
 @pytest.mark.usefixtures("async_environment")
 async def test_get(server):
     url = server.url
-    async with httpx.AsyncClient() as client:
+    async with httpx.AsyncClient(http2=True) as client:
         response = await client.get(url)
     assert response.status_code == 200
     assert response.text == "Hello, world!"
index a936e051945070b54a63c474f80baeb91cd71fce..b3e449677d014230c2e4051be9f24b8b750f0044 100644 (file)
@@ -7,7 +7,7 @@ import httpx
 
 def test_get(server):
     url = server.url
-    with httpx.Client() as http:
+    with httpx.Client(http2=True) as http:
         response = http.get(url)
     assert response.status_code == 200
     assert response.url == url