]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Rename Client to AsyncClient (with compat synonym) (#680)
authorFlorimond Manca <florimond.manca@gmail.com>
Sun, 29 Dec 2019 15:34:23 +0000 (16:34 +0100)
committerTom Christie <tom@tomchristie.com>
Sun, 29 Dec 2019 15:34:23 +0000 (15:34 +0000)
* Rename Client to AsyncClient (with compat synonym)

* Document motivation for AsyncClient renaming

Co-authored-by: Tom Christie <tom@tomchristie.com>
24 files changed:
docs/advanced.md
docs/api.md
docs/compatibility.md
docs/environment_variables.md
docs/http2.md
httpx/__init__.py
httpx/api.py
httpx/client.py
httpx/dispatch/asgi.py
httpx/dispatch/base.py
tests/client/test_async_client.py
tests/client/test_auth.py
tests/client/test_client.py
tests/client/test_cookies.py
tests/client/test_headers.py
tests/client/test_properties.py
tests/client/test_proxies.py
tests/client/test_queryparams.py
tests/client/test_redirects.py
tests/dispatch/test_http2.py
tests/test_asgi.py
tests/test_multipart.py
tests/test_timeouts.py
tests/test_utils.py

index 46e16cce49cd9daf6daf0514939b23ed40cc98e3..c3df1d136d6a0bab989add2c1f19fb78a4315a29 100644 (file)
@@ -9,12 +9,17 @@ all outgoing requests.
 !!! hint
     A Client instance is equivalent to a Session instance in `requests`.
 
+!!! note
+    Starting from `httpx==0.10.0`, the default and recommended Client class is `AsyncClient`. This should help prevent breaking changes once sync support is reintroduced.
+
+    A `Client` synonym remains for compatibility with `httpx==0.9.*` releases, but you are encouraged to migrate to `AsyncClient` as soon as possible.
+
 ### Usage
 
 The recommended way to use a `Client` is as a context manager. This will ensure that connections are properly cleaned up when leaving the `with` block:
 
 ```python
->>> async with httpx.Client() as client:
+>>> async with httpx.AsyncClient() as client:
 ...     r = await client.get('https://example.com')
 ...
 >>> r
@@ -24,7 +29,7 @@ The recommended way to use a `Client` is as a context manager. This will ensure
 Alternatively, you can explicitly close the connection pool without block-usage using `.aclose()`:
 
 ```python
->>> client = httpx.Client()
+>>> client = httpx.AsyncClient()
 >>> try:
 ...     r = await client.get('https://example.com')
 ... finally:
@@ -45,7 +50,7 @@ For example, to apply a set of custom headers on every request:
 ```python
 >>> url = 'http://httpbin.org/headers'
 >>> headers = {'user-agent': 'my-app/0.0.1'}
->>> async with httpx.Client(headers=headers) as client:
+>>> async with httpx.AsyncClient(headers=headers) as client:
 ...     r = await client.get(url)
 ...
 >>> r.json()['headers']['User-Agent']
@@ -58,19 +63,19 @@ For example, to apply a set of custom headers on every request:
     - For headers, query parameters and cookies, the values are merged into one.
     - For all other parameters, the request-level value is used.
 
-Additionally, `Client` constructor accepts some parameters that aren't available at the request level.
+Additionally, `Client` accepts some parameters that aren't available at the request level.
 
 One particularly useful parameter is `base_url`, which allows you to define a base URL to prepend to all outgoing requests:
 
 ```python
->>> async with httpx.Client(base_url='http://httpbin.org') as client:
+>>> async with httpx.AsyncClient(base_url='http://httpbin.org') as client:
 ...     r = await client.get('/headers')
 ...
 >>> r.request.url
 URL('http://httpbin.org/headers')
 ```
 
-For a list of all available client-level parameters, see the [`Client` API reference](/api/#client).
+For a list of all available client-level parameters, see the [`AsyncClient` API reference](/api/#async-client).
 
 ## Calling into Python Web Apps
 
@@ -101,7 +106,7 @@ We can make requests directly against the application, like so:
 
 ```python
 >>> import httpx
->>> async with httpx.Client(app=app) as client:
+>>> async with httpx.AsyncClient(app=app) as client:
 ...     r = client.get('http://example/')
 ...     assert r.status_code == 200
 ...     assert r.text == "Hello World!"
@@ -119,7 +124,7 @@ For example:
 # Instantiate a client that makes ASGI requests with a client IP of "1.2.3.4",
 # on port 123.
 dispatch = httpx.dispatch.ASGIDispatch(app=app, client=("1.2.3.4", 123))
-async with httpx.Client(dispatch=dispatch) as client:
+async with httpx.AsyncClient(dispatch=dispatch) as client:
     ...
 ```
 
@@ -132,7 +137,7 @@ You can use `Client.build_request()` to build a request and
 make modifications before sending the request.
 
 ```python
->>> async with httpx.Client() as client:
+>>> async with httpx.AsyncClient() as client:
 ...     req = client.build_request("OPTIONS", "https://example.com")
 ...     req.url.full_path = "*"  # Build an 'OPTIONS *' request for CORS
 ...     r = await client.send(req)
@@ -177,7 +182,7 @@ password example-password
 When using `Client` instances, `trust_env` should be set on the client itself, rather that on the request methods:
 
 ```python
-client = httpx.Client(trust_env=False)
+client = httpx.AsyncClient(trust_env=False)
 ```
 
 ## Unix Domain Sockets
@@ -190,7 +195,7 @@ Here's an example requesting the Docker Engine API:
 import httpx
 
 
-async with httpx.Client(uds="/var/run/docker.sock") as client:
+async with httpx.AsyncClient(uds="/var/run/docker.sock") as client:
     # This request will connect through the socket file.
     resp = await client.get("http://localhost/version")
 ```
@@ -206,7 +211,7 @@ to `http://127.0.0.1:3081` your `proxies` config would look like this:
 ...     "http": "http://127.0.0.1:3080",
 ...     "https": "http://127.0.0.1:3081"
 ... }
->>> async with httpx.Client(proxies=proxies) as client:
+>>> async with httpx.AsyncClient(proxies=proxies) as client:
 ...     ...
 ```
 
@@ -221,11 +226,11 @@ to use for a given request this same order is used.
 ...     "http": "...",  # Scheme
 ...     "all": "...",  # All
 ... }
->>> async with httpx.Client(proxies=proxies) as client:
+>>> async with httpx.AsyncClient(proxies=proxies) as client:
 ...     ...
 ...
 >>> proxy = "..."  # Shortcut for {'all': '...'}
->>> async with httpx.Client(proxies=proxy) as client:
+>>> async with httpx.AsyncClient(proxies=proxy) as client:
 ...     ...
 ```
 
@@ -245,7 +250,7 @@ proxy = httpx.HTTPProxy(
     proxy_url="https://127.0.0.1",
     proxy_mode="TUNNEL_ONLY"  # May be "TUNNEL_ONLY" or "FORWARD_ONLY". Defaults to "DEFAULT".
 )
-async with httpx.Client(proxies=proxy) as client:
+async with httpx.AsyncClient(proxies=proxy) as client:
     # This request will be tunneled instead of forwarded.
     r = await client.get("http://example.com")
 ```
@@ -272,7 +277,7 @@ You can set timeouts for an individual request:
 await httpx.get('http://example.com/api/v1/example', timeout=10.0)
 
 # Using a client instance:
-async with httpx.Client() as client:
+async with httpx.AsyncClient() as client:
     await client.get("http://example.com/api/v1/example", timeout=10.0)
 ```
 
@@ -283,7 +288,7 @@ Or disable timeouts for an individual request:
 await httpx.get('http://example.com/api/v1/example', timeout=None)
 
 # Using a client instance:
-async with httpx.Client() as client:
+async with httpx.AsyncClient() as client:
     await client.get("http://example.com/api/v1/example", timeout=None)
 ```
 
@@ -293,9 +298,9 @@ You can set a timeout on a client instance, which results in the given
 `timeout` being used as the default for requests made with this client:
 
 ```python
-client = httpx.Client()              # Use a default 5s timeout everywhere.
-client = httpx.Client(timeout=10.0)  # Use a default 10s timeout everywhere.
-client = httpx.Client(timeout=None)  # Disable all timeouts by default.
+client = httpx.AsyncClient()              # Use a default 5s timeout everywhere.
+client = httpx.AsyncClient(timeout=10.0)  # Use a default 10s timeout everywhere.
+client = httpx.AsyncClient(timeout=None)  # Disable all timeouts by default.
 ```
 
 ### Fine tuning the configuration
@@ -325,7 +330,7 @@ You can configure the timeout behavior for any of these values...
 ```python
 # A client with a 60s timeout for connecting, and a 10s timeout elsewhere.
 timeout = httpx.Timeout(10.0, connect_timeout=60.0)
-client = httpx.Client(timeout=timeout)
+client = httpx.AsyncClient(timeout=timeout)
 
 response = await client.get('http://example.com/')
 ```
@@ -404,7 +409,7 @@ r = await httpx.get("https://example.org", verify=False)
 If you're using a `Client()` instance, then you should pass any SSL settings when instantiating the client.
 
 ```python
-client = httpx.Client(verify=False)
+client = httpx.AsyncClient(verify=False)
 ```
 
 The `client.get(...)` method and other request methods *do not* support changing the SSL settings on a per-request basis. If you need different SSL settings in different cases you should use more that one client instance, with different settings on each. Each client will then be using an isolated connection pool with a specific fixed SSL configuration on all connections within that pool.
@@ -437,9 +442,9 @@ You can also explicitly select a backend by instantiating a client with the
 `backend` argument...
 
 ```python
-client = httpx.Client(backend='auto')     # Autodetection. The default case.
-client = httpx.Client(backend='asyncio')  # Use asyncio as the backend.
-client = httpx.Client(backend='trio')     # Use trio as the backend.
+client = httpx.AsyncClient(backend='auto')     # Autodetection. The default case.
+client = httpx.AsyncClient(backend='asyncio')  # Use asyncio as the backend.
+client = httpx.AsyncClient(backend='trio')     # Use trio as the backend.
 ```
 
 ### [AsyncIO](https://docs.python.org/3/library/asyncio.html)
@@ -452,7 +457,7 @@ import asyncio
 import httpx
 
 async def main():
-    client = httpx.Client()
+    client = httpx.AsyncClient()
     response = await client.get('https://www.example.com/')
     print(response)
 
@@ -469,7 +474,7 @@ import httpx
 import trio
 
 async def main():
-    client = httpx.Client()
+    client = httpx.AsyncClient()
     response = await client.get('https://www.example.com/')
     print(response)
 
index 3b28fb3828fccb016cc52f03d5e2e538d68ac14d..3f45c906524d465715e2c158b870dee0af91df9d 100644 (file)
@@ -32,9 +32,9 @@
 ::: httpx.delete
     :docstring:
 
-## `Client`
+## `AsyncClient`
 
-::: httpx.Client
+::: httpx.AsyncClient
     :docstring:
     :members: headers cookies params request get head options post put patch delete build_request send aclose
 
index 6f67660ba51ec6638cfe5f1745a7c2965e5c4366..fc3a615731e5f25c41a6ba6fa3aac878f24cfa6e 100644 (file)
@@ -52,7 +52,7 @@ We don't support `response.is_ok` since the naming is ambiguous there, and might
 
 ## Client instances
 
-The HTTPX equivalent of `requests.Session` is `httpx.Client`.
+The HTTPX equivalent of `requests.Session` is `httpx.AsyncClient`.
 
 ```python
 session = requests.Session(**kwargs)
@@ -61,7 +61,7 @@ session = requests.Session(**kwargs)
 is generally equivalent to
 
 ```python
-client = httpx.Client(**kwargs)
+client = httpx.AsyncClient(**kwargs)
 ```
 
 ## Mocking
index bd41c83d79208940a5678ceba3c8b3f9aec3c568..6289d030551f97b423ec8a1b0867a5fa7a76e4ca 100644 (file)
@@ -4,7 +4,7 @@ Environment Variables
 The HTTPX library can be configured via environment variables.
 Environment variables are used by default. To ignore environment variables, `trust_env` has to be set `False`. There are two ways to set `trust_env` to disable environment variables:
 
-* On the client via `httpx.Client(trust_env=False)`.
+* On the client via `httpx.AsyncClient(trust_env=False)`.
 * Using the top-level API, such as `httpx.get("<url>", trust_env=False)`.
 
 Here is a list of environment variables that HTTPX recognizes and what function they serve:
@@ -24,7 +24,7 @@ Example:
 # test_script.py
 import httpx
 
-with httpx.Client() as client:
+with httpx.AsyncClient() as client:
     r = client.get("https://google.com")
 ```
 
@@ -89,7 +89,7 @@ Example:
 # test_script.py
 import httpx
 
-with httpx.Client() as client:
+with httpx.AsyncClient() as client:
     r = client.get("https://google.com")
 ```
 
index ed960e3187aff05cf3544cd9e67756a26131c3b2..25705bf289ecd4145847e7b0992c09448d753f62 100644 (file)
@@ -30,7 +30,7 @@ trying out our HTTP/2 support. You can do so by instantiating a client with
 HTTP/2 support enabled:
 
 ```python
-client = httpx.Client(http2=True)
+client = httpx.AsyncClient(http2=True)
 ...
 ```
 
@@ -39,7 +39,7 @@ HTTP connections are nicely scoped, and will be closed once the context block
 is exited.
 
 ```python
-async with httpx.Client(http2=True) as client:
+async with httpx.AsyncClient(http2=True) as client:
     ...
 ```
 
@@ -54,7 +54,7 @@ You can determine which version of the HTTP protocol was used by examining
 the `.http_version` property on the response.
 
 ```python
-client = httpx.Client(http2=True)
+client = httpx.AsyncClient(http2=True)
 response = await client.get(...)
 print(response.http_version)  # "HTTP/1.0", "HTTP/1.1", or "HTTP/2".
 ```
index ce92f88593c41cef7e33f195d046bc0b55f80a2d..61346d0e63b02bbc350584aa7fd7f3ac2460fc68 100644 (file)
@@ -1,7 +1,7 @@
 from .__version__ import __description__, __title__, __version__
 from .api import delete, get, head, options, patch, post, put, request, stream
 from .auth import BasicAuth, DigestAuth
-from .client import Client
+from .client import AsyncClient, Client
 from .config import TimeoutConfig  # For 0.8 backwards compat.
 from .config import PoolLimits, Timeout
 from .dispatch.proxy_http import HTTPProxy, HTTPProxyMode
@@ -44,6 +44,7 @@ __all__ = [
     "request",
     "stream",
     "codes",
+    "AsyncClient",
     "BasicAuth",
     "Client",
     "DigestAuth",
index ccf7a346a95de0e16608ac53a31c4916f15e6563..c8b9f65f883b814fc06d02f616473a434e24d0e2 100644 (file)
@@ -1,7 +1,7 @@
 import typing
 
 from .auth import AuthTypes
-from .client import Client, StreamContextManager
+from .client import AsyncClient, StreamContextManager
 from .config import DEFAULT_TIMEOUT_CONFIG, CertTypes, TimeoutTypes, VerifyTypes
 from .models import (
     CookieTypes,
@@ -81,7 +81,7 @@ async def request(
     <Response [200 OK]>
     ```
     """
-    async with Client(
+    async with AsyncClient(
         cert=cert, verify=verify, timeout=timeout, trust_env=trust_env,
     ) as client:
         return await client.request(
@@ -116,7 +116,7 @@ def stream(
     cert: CertTypes = None,
     trust_env: bool = True,
 ) -> StreamContextManager:
-    client = Client(cert=cert, verify=verify, trust_env=trust_env)
+    client = AsyncClient(cert=cert, verify=verify, trust_env=trust_env)
     request = Request(
         method=method,
         url=url,
index d01707858bbf522cc7e5d9f1dd59454a46592159..d2ae2fc976b42c7e23fdae6867066ed590603b99 100644 (file)
@@ -52,14 +52,15 @@ from .utils import ElapsedTimer, NetRCInfo, get_environment_proxies, get_logger
 logger = get_logger(__name__)
 
 
-class Client:
+class AsyncClient:
     """
-    An HTTP client, with connection pooling, HTTP/2, redirects, cookie persistence, etc.
+    An asynchronous HTTP client, with connection pooling, HTTP/2, redirects,
+    cookie persistence, etc.
 
     Usage:
 
-    ```
-    >>> client = httpx.Client()
+    ```python
+    >>> client = httpx.AsyncClient()
     >>> response = client.get('https://example.org')
     ```
 
@@ -868,7 +869,7 @@ class Client:
     async def aclose(self) -> None:
         await self.dispatch.close()
 
-    async def __aenter__(self) -> "Client":
+    async def __aenter__(self) -> "AsyncClient":
         return self
 
     async def __aexit__(
@@ -923,7 +924,7 @@ def _proxies_to_dispatchers(
 class StreamContextManager:
     def __init__(
         self,
-        client: Client,
+        client: AsyncClient,
         request: Request,
         *,
         auth: AuthTypes = None,
@@ -957,3 +958,7 @@ class StreamContextManager:
         await self.response.aclose()
         if self.close_client:
             await self.client.aclose()
+
+
+# For compatibility with 0.9.x.
+Client = AsyncClient
index a314ec370b52bc8014d245a55047c9ca4137e397..2f74019e28447ef69adee40f39e61fefcd3af597 100644 (file)
@@ -15,7 +15,7 @@ class ASGIDispatch(Dispatcher):
     and will setup an appropriate dispatch class:
 
     ```
-    client = httpx.Client(app=app)
+    client = httpx.AsyncClient(app=app)
     ```
 
     Alternatively, you can setup the dispatch instance explicitly.
@@ -28,7 +28,7 @@ class ASGIDispatch(Dispatcher):
         root_path="/submount",
         client=("1.2.3.4", 123)
     )
-    client = httpx.Client(dispatch=dispatch)
+    client = httpx.AsyncClient(dispatch=dispatch)
     ```
 
     Arguments:
index 7dccfab787c1bb4ae8a4a63734af373f04abe0e6..69073b01ae9ce11577c8373f40a367364e9a10a2 100644 (file)
@@ -18,7 +18,7 @@ class Dispatcher:
 
     Stubs out the interface, as well as providing a `.request()` convenience
     implementation, to make it easy to use or test stand-alone dispatchers,
-    without requiring a complete `Client` instance.
+    without requiring a complete `AsyncClient` instance.
     """
 
     async def request(
index 20216b6f5d1350745640cfdfb332eb4d66601037..59438399669860542b98a07a13c09d5a23a6847c 100644 (file)
@@ -8,7 +8,7 @@ import httpx
 @pytest.mark.usefixtures("async_environment")
 async def test_get(server):
     url = server.url
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         response = await client.get(url)
     assert response.status_code == 200
     assert response.text == "Hello, world!"
@@ -22,7 +22,7 @@ async def test_get(server):
 async def test_build_request(server):
     url = server.url.copy_with(path="/echo_headers")
     headers = {"Custom-header": "value"}
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         request = client.build_request("GET", url)
         request.headers.update(headers)
         response = await client.send(request)
@@ -36,7 +36,7 @@ async def test_build_request(server):
 @pytest.mark.usefixtures("async_environment")
 async def test_post(server):
     url = server.url
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         response = await client.post(url, data=b"Hello, world!")
     assert response.status_code == 200
 
@@ -44,14 +44,14 @@ async def test_post(server):
 @pytest.mark.usefixtures("async_environment")
 async def test_post_json(server):
     url = server.url
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         response = await client.post(url, json={"text": "Hello, world!"})
     assert response.status_code == 200
 
 
 @pytest.mark.usefixtures("async_environment")
 async def test_stream_response(server):
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         async with client.stream("GET", server.url) as response:
             body = await response.aread()
 
@@ -62,7 +62,7 @@ async def test_stream_response(server):
 
 @pytest.mark.usefixtures("async_environment")
 async def test_access_content_stream_response(server):
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         async with client.stream("GET", server.url) as response:
             pass
 
@@ -77,14 +77,14 @@ async def test_stream_request(server):
         yield b"Hello, "
         yield b"world!"
 
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         response = await client.request("POST", server.url, data=hello_world())
     assert response.status_code == 200
 
 
 @pytest.mark.usefixtures("async_environment")
 async def test_raise_for_status(server):
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         for status_code in (200, 400, 404, 500, 505):
             response = await client.request(
                 "GET", server.url.copy_with(path=f"/status/{status_code}")
@@ -100,7 +100,7 @@ async def test_raise_for_status(server):
 
 @pytest.mark.usefixtures("async_environment")
 async def test_options(server):
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         response = await client.options(server.url)
     assert response.status_code == 200
     assert response.text == "Hello, world!"
@@ -108,7 +108,7 @@ async def test_options(server):
 
 @pytest.mark.usefixtures("async_environment")
 async def test_head(server):
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         response = await client.head(server.url)
     assert response.status_code == 200
     assert response.text == ""
@@ -116,21 +116,21 @@ async def test_head(server):
 
 @pytest.mark.usefixtures("async_environment")
 async def test_put(server):
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         response = await client.put(server.url, data=b"Hello, world!")
     assert response.status_code == 200
 
 
 @pytest.mark.usefixtures("async_environment")
 async def test_patch(server):
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         response = await client.patch(server.url, data=b"Hello, world!")
     assert response.status_code == 200
 
 
 @pytest.mark.usefixtures("async_environment")
 async def test_delete(server):
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         response = await client.delete(server.url)
     assert response.status_code == 200
     assert response.text == "Hello, world!"
@@ -141,7 +141,7 @@ async def test_100_continue(server):
     headers = {"Expect": "100-continue"}
     data = b"Echo request body"
 
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         response = await client.post(
             server.url.copy_with(path="/echo_body"), headers=headers, data=data
         )
@@ -155,7 +155,7 @@ async def test_uds(uds_server):
     url = uds_server.url
     uds = uds_server.config.uds
     assert uds is not None
-    async with httpx.Client(uds=uds) as client:
+    async with httpx.AsyncClient(uds=uds) as client:
         response = await client.get(url)
     assert response.status_code == 200
     assert response.text == "Hello, world!"
@@ -163,7 +163,7 @@ async def test_uds(uds_server):
 
 
 async def test_explicit_backend(server, async_environment):
-    async with httpx.Client(backend=async_environment) as client:
+    async with httpx.AsyncClient(backend=async_environment) as client:
         response = await client.get(server.url)
     assert response.status_code == 200
     assert response.text == "Hello, world!"
index 2d76c4cc753a4d977d2cac2f8e1ec597ed26213e..d4dd76a905c2e4f12c2c0bb4761d23b18d048f4e 100644 (file)
@@ -5,7 +5,7 @@ import typing
 
 import pytest
 
-from httpx import URL, Client, DigestAuth, ProtocolError, Request, Response
+from httpx import URL, AsyncClient, DigestAuth, ProtocolError, Request, Response
 from httpx.config import CertTypes, TimeoutTypes, VerifyTypes
 from httpx.dispatch.base import Dispatcher
 
@@ -89,7 +89,7 @@ async def test_basic_auth() -> None:
     url = "https://example.org/"
     auth = ("tomchristie", "password123")
 
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     response = await client.get(url, auth=auth)
 
     assert response.status_code == 200
@@ -100,7 +100,7 @@ async def test_basic_auth() -> None:
 async def test_basic_auth_in_url() -> None:
     url = "https://tomchristie:password123@example.org/"
 
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     response = await client.get(url)
 
     assert response.status_code == 200
@@ -112,7 +112,7 @@ async def test_basic_auth_on_session() -> None:
     url = "https://example.org/"
     auth = ("tomchristie", "password123")
 
-    client = Client(dispatch=MockDispatch(), auth=auth)
+    client = AsyncClient(dispatch=MockDispatch(), auth=auth)
     response = await client.get(url)
 
     assert response.status_code == 200
@@ -127,7 +127,7 @@ async def test_custom_auth() -> None:
         request.headers["Authorization"] = "Token 123"
         return request
 
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     response = await client.get(url, auth=auth)
 
     assert response.status_code == 200
@@ -139,7 +139,7 @@ async def test_netrc_auth() -> None:
     os.environ["NETRC"] = "tests/.netrc"
     url = "http://netrcexample.org"
 
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     response = await client.get(url)
 
     assert response.status_code == 200
@@ -153,7 +153,7 @@ async def test_auth_header_has_priority_over_netrc() -> None:
     os.environ["NETRC"] = "tests/.netrc"
     url = "http://netrcexample.org"
 
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     response = await client.get(url, headers={"Authorization": "Override"})
 
     assert response.status_code == 200
@@ -165,13 +165,13 @@ async def test_trust_env_auth() -> None:
     os.environ["NETRC"] = "tests/.netrc"
     url = "http://netrcexample.org"
 
-    client = Client(dispatch=MockDispatch(), trust_env=False)
+    client = AsyncClient(dispatch=MockDispatch(), trust_env=False)
     response = await client.get(url)
 
     assert response.status_code == 200
     assert response.json() == {"auth": None}
 
-    client = Client(dispatch=MockDispatch(), trust_env=True)
+    client = AsyncClient(dispatch=MockDispatch(), trust_env=True)
     response = await client.get(url)
 
     assert response.status_code == 200
@@ -192,7 +192,7 @@ async def test_auth_hidden_header() -> None:
     url = "https://example.org/"
     auth = ("example-username", "example-password")
 
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     response = await client.get(url, auth=auth)
 
     assert "'authorization': '[secure]'" in str(response.request.headers)
@@ -201,7 +201,7 @@ async def test_auth_hidden_header() -> None:
 @pytest.mark.asyncio
 async def test_auth_invalid_type() -> None:
     url = "https://example.org/"
-    client = Client(
+    client = AsyncClient(
         dispatch=MockDispatch(), auth="not a tuple, not a callable",  # type: ignore
     )
     with pytest.raises(TypeError):
@@ -213,7 +213,7 @@ async def test_digest_auth_returns_no_auth_if_no_digest_header_in_response() ->
     url = "https://example.org/"
     auth = DigestAuth(username="tomchristie", password="password123")
 
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     response = await client.get(url, auth=auth)
 
     assert response.status_code == 200
@@ -226,7 +226,9 @@ async def test_digest_auth_200_response_including_digest_auth_header() -> None:
     auth = DigestAuth(username="tomchristie", password="password123")
     auth_header = 'Digest realm="realm@host.com",qop="auth",nonce="abc",opaque="xyz"'
 
-    client = Client(dispatch=MockDispatch(auth_header=auth_header, status_code=200))
+    client = AsyncClient(
+        dispatch=MockDispatch(auth_header=auth_header, status_code=200)
+    )
     response = await client.get(url, auth=auth)
 
     assert response.status_code == 200
@@ -238,7 +240,7 @@ async def test_digest_auth_401_response_without_digest_auth_header() -> None:
     url = "https://example.org/"
     auth = DigestAuth(username="tomchristie", password="password123")
 
-    client = Client(dispatch=MockDispatch(auth_header="", status_code=401))
+    client = AsyncClient(dispatch=MockDispatch(auth_header="", status_code=401))
     response = await client.get(url, auth=auth)
 
     assert response.status_code == 401
@@ -265,7 +267,7 @@ async def test_digest_auth(
     url = "https://example.org/"
     auth = DigestAuth(username="tomchristie", password="password123")
 
-    client = Client(dispatch=MockDigestAuthDispatch(algorithm=algorithm))
+    client = AsyncClient(dispatch=MockDigestAuthDispatch(algorithm=algorithm))
     response = await client.get(url, auth=auth)
 
     assert response.status_code == 200
@@ -293,7 +295,7 @@ async def test_digest_auth_no_specified_qop() -> None:
     url = "https://example.org/"
     auth = DigestAuth(username="tomchristie", password="password123")
 
-    client = Client(dispatch=MockDigestAuthDispatch(qop=""))
+    client = AsyncClient(dispatch=MockDigestAuthDispatch(qop=""))
     response = await client.get(url, auth=auth)
 
     assert response.status_code == 200
@@ -322,7 +324,7 @@ async def test_digest_auth_qop_including_spaces_and_auth_returns_auth(qop: str)
     url = "https://example.org/"
     auth = DigestAuth(username="tomchristie", password="password123")
 
-    client = Client(dispatch=MockDigestAuthDispatch(qop=qop))
+    client = AsyncClient(dispatch=MockDigestAuthDispatch(qop=qop))
     await client.get(url, auth=auth)
 
 
@@ -330,7 +332,7 @@ async def test_digest_auth_qop_including_spaces_and_auth_returns_auth(qop: str)
 async def test_digest_auth_qop_auth_int_not_implemented() -> None:
     url = "https://example.org/"
     auth = DigestAuth(username="tomchristie", password="password123")
-    client = Client(dispatch=MockDigestAuthDispatch(qop="auth-int"))
+    client = AsyncClient(dispatch=MockDigestAuthDispatch(qop="auth-int"))
 
     with pytest.raises(NotImplementedError):
         await client.get(url, auth=auth)
@@ -340,7 +342,7 @@ async def test_digest_auth_qop_auth_int_not_implemented() -> None:
 async def test_digest_auth_qop_must_be_auth_or_auth_int() -> None:
     url = "https://example.org/"
     auth = DigestAuth(username="tomchristie", password="password123")
-    client = Client(dispatch=MockDigestAuthDispatch(qop="not-auth"))
+    client = AsyncClient(dispatch=MockDigestAuthDispatch(qop="not-auth"))
 
     with pytest.raises(ProtocolError):
         await client.get(url, auth=auth)
@@ -351,7 +353,7 @@ async def test_digest_auth_incorrect_credentials() -> None:
     url = "https://example.org/"
     auth = DigestAuth(username="tomchristie", password="password123")
 
-    client = Client(dispatch=MockDigestAuthDispatch(send_response_after_attempt=2))
+    client = AsyncClient(dispatch=MockDigestAuthDispatch(send_response_after_attempt=2))
     response = await client.get(url, auth=auth)
 
     assert response.status_code == 401
@@ -373,7 +375,9 @@ async def test_digest_auth_raises_protocol_error_on_malformed_header(
 ) -> None:
     url = "https://example.org/"
     auth = DigestAuth(username="tomchristie", password="password123")
-    client = Client(dispatch=MockDispatch(auth_header=auth_header, status_code=401))
+    client = AsyncClient(
+        dispatch=MockDispatch(auth_header=auth_header, status_code=401)
+    )
 
     with pytest.raises(ProtocolError):
         await client.get(url, auth=auth)
index 05abedf1f5ff51b1b218b23fd7b5fff0ec0946f1..7c877224049664386c311cf79156f46b0601be40 100644 (file)
@@ -8,7 +8,7 @@ import httpx
 @pytest.mark.asyncio
 async def test_get(server):
     url = server.url
-    async with httpx.Client() as http:
+    async with httpx.AsyncClient() as http:
         response = await http.get(url)
     assert response.status_code == 200
     assert response.url == url
@@ -28,7 +28,7 @@ async def test_build_request(server):
     url = server.url.copy_with(path="/echo_headers")
     headers = {"Custom-header": "value"}
 
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         request = client.build_request("GET", url)
         request.headers.update(headers)
         response = await client.send(request)
@@ -41,7 +41,7 @@ async def test_build_request(server):
 
 @pytest.mark.asyncio
 async def test_post(server):
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         response = await client.post(server.url, data=b"Hello, world!")
     assert response.status_code == 200
     assert response.reason_phrase == "OK"
@@ -49,7 +49,7 @@ async def test_post(server):
 
 @pytest.mark.asyncio
 async def test_post_json(server):
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         response = await client.post(server.url, json={"text": "Hello, world!"})
     assert response.status_code == 200
     assert response.reason_phrase == "OK"
@@ -57,7 +57,7 @@ async def test_post_json(server):
 
 @pytest.mark.asyncio
 async def test_stream_response(server):
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         async with client.stream("GET", server.url) as response:
             content = await response.aread()
     assert response.status_code == 200
@@ -68,7 +68,7 @@ async def test_stream_response(server):
 async def test_stream_iterator(server):
     body = b""
 
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         async with client.stream("GET", server.url) as response:
             async for chunk in response.aiter_bytes():
                 body += chunk
@@ -81,7 +81,7 @@ async def test_stream_iterator(server):
 async def test_raw_iterator(server):
     body = b""
 
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         async with client.stream("GET", server.url) as response:
             async for chunk in response.aiter_raw():
                 body += chunk
@@ -92,7 +92,7 @@ async def test_raw_iterator(server):
 
 @pytest.mark.asyncio
 async def test_raise_for_status(server):
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         for status_code in (200, 400, 404, 500, 505):
             response = await client.request(
                 "GET", server.url.copy_with(path="/status/{}".format(status_code))
@@ -107,7 +107,7 @@ async def test_raise_for_status(server):
 
 @pytest.mark.asyncio
 async def test_options(server):
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         response = await client.options(server.url)
     assert response.status_code == 200
     assert response.reason_phrase == "OK"
@@ -115,7 +115,7 @@ async def test_options(server):
 
 @pytest.mark.asyncio
 async def test_head(server):
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         response = await client.head(server.url)
     assert response.status_code == 200
     assert response.reason_phrase == "OK"
@@ -123,7 +123,7 @@ async def test_head(server):
 
 @pytest.mark.asyncio
 async def test_put(server):
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         response = await client.put(server.url, data=b"Hello, world!")
     assert response.status_code == 200
     assert response.reason_phrase == "OK"
@@ -131,7 +131,7 @@ async def test_put(server):
 
 @pytest.mark.asyncio
 async def test_patch(server):
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         response = await client.patch(server.url, data=b"Hello, world!")
     assert response.status_code == 200
     assert response.reason_phrase == "OK"
@@ -139,7 +139,7 @@ async def test_patch(server):
 
 @pytest.mark.asyncio
 async def test_delete(server):
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         response = await client.delete(server.url)
     assert response.status_code == 200
     assert response.reason_phrase == "OK"
@@ -148,7 +148,7 @@ async def test_delete(server):
 @pytest.mark.asyncio
 async def test_base_url(server):
     base_url = server.url
-    async with httpx.Client(base_url=base_url) as client:
+    async with httpx.AsyncClient(base_url=base_url) as client:
         response = await client.get("/")
     assert response.status_code == 200
     assert response.url == base_url
@@ -159,7 +159,7 @@ async def test_uds(uds_server):
     url = uds_server.url
     uds = uds_server.config.uds
     assert uds is not None
-    async with httpx.Client(uds=uds) as client:
+    async with httpx.AsyncClient(uds=uds) as client:
         response = await client.get(url)
     assert response.status_code == 200
     assert response.text == "Hello, world!"
@@ -167,7 +167,7 @@ async def test_uds(uds_server):
 
 
 def test_merge_url():
-    client = httpx.Client(base_url="https://www.paypal.com/")
+    client = httpx.AsyncClient(base_url="https://www.paypal.com/")
     url = client.merge_url("http://www.paypal.com")
 
     assert url.scheme == "https"
@@ -177,6 +177,6 @@ def test_merge_url():
 @pytest.mark.asyncio
 async def test_elapsed_delay(server):
     url = server.url.copy_with(path="/slow_response/100")
-    async with httpx.Client() as client:
+    async with httpx.AsyncClient() as client:
         response = await client.get(url)
     assert response.elapsed.total_seconds() > 0.0
index e73a590b53b7f71f51ef1d5d99bd366bd3909081..3e8d0d3b18c5548540d8954934f3681c04e183d2 100644 (file)
@@ -3,7 +3,7 @@ from http.cookiejar import Cookie, CookieJar
 
 import pytest
 
-from httpx import Client, Cookies, Request, Response
+from httpx import AsyncClient, Cookies, Request, Response
 from httpx.config import CertTypes, TimeoutTypes, VerifyTypes
 from httpx.dispatch.base import Dispatcher
 
@@ -34,7 +34,7 @@ async def test_set_cookie() -> None:
     url = "http://example.org/echo_cookies"
     cookies = {"example-name": "example-value"}
 
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     response = await client.get(url, cookies=cookies)
 
     assert response.status_code == 200
@@ -70,7 +70,7 @@ async def test_set_cookie_with_cookiejar() -> None:
     )
     cookies.set_cookie(cookie)
 
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     response = await client.get(url, cookies=cookies)
 
     assert response.status_code == 200
@@ -106,7 +106,7 @@ async def test_setting_client_cookies_to_cookiejar() -> None:
     )
     cookies.set_cookie(cookie)
 
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     client.cookies = cookies  # type: ignore
     response = await client.get(url)
 
@@ -124,7 +124,7 @@ async def test_set_cookie_with_cookies_model() -> None:
     cookies = Cookies()
     cookies["example-name"] = "example-value"
 
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     response = await client.get(url, cookies=cookies)
 
     assert response.status_code == 200
@@ -135,7 +135,7 @@ async def test_set_cookie_with_cookies_model() -> None:
 async def test_get_cookie() -> None:
     url = "http://example.org/set_cookie"
 
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     response = await client.get(url)
 
     assert response.status_code == 200
@@ -148,7 +148,7 @@ async def test_cookie_persistence() -> None:
     """
     Ensure that Client instances persist cookies between requests.
     """
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
 
     response = await client.get("http://example.org/echo_cookies")
     assert response.status_code == 200
index 168b6a04df2c88e7bb39a2076f85855666758510..672092d8e8da18282899abf971ef007612f3d96e 100755 (executable)
@@ -4,7 +4,7 @@ import json
 
 import pytest
 
-from httpx import Client, Headers, Request, Response, __version__
+from httpx import AsyncClient, Headers, Request, Response, __version__
 from httpx.config import CertTypes, TimeoutTypes, VerifyTypes
 from httpx.dispatch.base import Dispatcher
 
@@ -31,7 +31,7 @@ async def test_client_header():
     url = "http://example.org/echo_headers"
     headers = {"Example-Header": "example-value"}
 
-    client = Client(dispatch=MockDispatch(), headers=headers)
+    client = AsyncClient(dispatch=MockDispatch(), headers=headers)
     response = await client.get(url)
 
     assert response.status_code == 200
@@ -52,7 +52,7 @@ async def test_header_merge():
     url = "http://example.org/echo_headers"
     client_headers = {"User-Agent": "python-myclient/0.2.1"}
     request_headers = {"X-Auth-Token": "FooBarBazToken"}
-    client = Client(dispatch=MockDispatch(), headers=client_headers)
+    client = AsyncClient(dispatch=MockDispatch(), headers=client_headers)
     response = await client.get(url, headers=request_headers)
 
     assert response.status_code == 200
@@ -73,7 +73,7 @@ async def test_header_merge_conflicting_headers():
     url = "http://example.org/echo_headers"
     client_headers = {"X-Auth-Token": "FooBar"}
     request_headers = {"X-Auth-Token": "BazToken"}
-    client = Client(dispatch=MockDispatch(), headers=client_headers)
+    client = AsyncClient(dispatch=MockDispatch(), headers=client_headers)
     response = await client.get(url, headers=request_headers)
 
     assert response.status_code == 200
@@ -92,7 +92,7 @@ async def test_header_merge_conflicting_headers():
 @pytest.mark.asyncio
 async def test_header_update():
     url = "http://example.org/echo_headers"
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     first_response = await client.get(url)
     client.headers.update(
         {"User-Agent": "python-myclient/0.2.1", "Another-Header": "AThing"}
@@ -138,7 +138,7 @@ async def test_host_with_auth_and_port_in_url():
     """
     url = "http://username:password@example.org:80/echo_headers"
 
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     response = await client.get(url)
 
     assert response.status_code == 200
@@ -162,7 +162,7 @@ async def test_host_with_non_default_port_in_url():
     """
     url = "http://username:password@example.org:123/echo_headers"
 
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     response = await client.get(url)
 
     assert response.status_code == 200
index f0ce671926e768e9c53cf032e0cb6bcfb8918cdd..5dbbb4690ad6ee3ffc23064975947e260af718be 100644 (file)
@@ -1,15 +1,15 @@
-from httpx import Client, Cookies, Headers
+from httpx import AsyncClient, Cookies, Headers
 
 
 def test_client_headers():
-    client = Client()
+    client = AsyncClient()
     client.headers = {"a": "b"}
     assert isinstance(client.headers, Headers)
     assert client.headers["A"] == "b"
 
 
 def test_client_cookies():
-    client = Client()
+    client = AsyncClient()
     client.cookies = {"a": "b"}
     assert isinstance(client.cookies, Cookies)
     mycookies = list(client.cookies.jar)
index 2e05b8644c6b9125349efbed85c908bf2f40ef3a..ff117147573e8b0be638fa55d566b3b0c3fe690a 100644 (file)
@@ -20,7 +20,7 @@ import httpx
     ],
 )
 def test_proxies_parameter(proxies, expected_proxies):
-    client = httpx.Client(proxies=proxies)
+    client = httpx.AsyncClient(proxies=proxies)
 
     for proxy_key, url in expected_proxies:
         assert proxy_key in client.proxies
@@ -30,7 +30,7 @@ def test_proxies_parameter(proxies, expected_proxies):
 
 
 def test_proxies_has_same_properties_as_dispatch():
-    client = httpx.Client(
+    client = httpx.AsyncClient(
         proxies="http://127.0.0.1",
         verify="/path/to/verify",
         cert="/path/to/cert",
@@ -96,7 +96,7 @@ PROXY_URL = "http://[::1]"
     ],
 )
 def test_dispatcher_for_request(url, proxies, expected):
-    client = httpx.Client(proxies=proxies)
+    client = httpx.AsyncClient(proxies=proxies)
     dispatcher = client.dispatcher_for_url(httpx.URL(url))
 
     if expected is None:
@@ -108,4 +108,4 @@ def test_dispatcher_for_request(url, proxies, expected):
 
 def test_unsupported_proxy_scheme():
     with pytest.raises(ValueError):
-        httpx.Client(proxies="ftp://127.0.0.1")
+        httpx.AsyncClient(proxies="ftp://127.0.0.1")
index 9417aab156b363df53d3e3ab3b4109a4d926baba..a887f1c2940f721c780d7e13bad38a39072e3442 100644 (file)
@@ -2,7 +2,7 @@ import json
 
 import pytest
 
-from httpx import URL, Client, QueryParams, Request, Response
+from httpx import URL, AsyncClient, QueryParams, Request, Response
 from httpx.config import CertTypes, TimeoutTypes, VerifyTypes
 from httpx.dispatch.base import Dispatcher
 
@@ -21,17 +21,17 @@ class MockDispatch(Dispatcher):
 
 
 def test_client_queryparams():
-    client = Client(params={"a": "b"})
+    client = AsyncClient(params={"a": "b"})
     assert isinstance(client.params, QueryParams)
     assert client.params["a"] == "b"
 
 
 def test_client_queryparams_string():
-    client = Client(params="a=b")
+    client = AsyncClient(params="a=b")
     assert isinstance(client.params, QueryParams)
     assert client.params["a"] == "b"
 
-    client = Client()
+    client = AsyncClient()
     client.params = "a=b"
     assert isinstance(client.params, QueryParams)
     assert client.params["a"] == "b"
@@ -42,7 +42,7 @@ async def test_client_queryparams_echo():
     url = "http://example.org/echo_queryparams"
     client_queryparams = "first=str"
     request_queryparams = {"second": "dict"}
-    client = Client(dispatch=MockDispatch(), params=client_queryparams)
+    client = AsyncClient(dispatch=MockDispatch(), params=client_queryparams)
     response = await client.get(url, params=request_queryparams)
 
     assert response.status_code == 200
index 8ad81fee3897444d97049f991d969edf056a4e59..fdce8ca9239b1dedfb7aa10d94f0e73177e79271 100644 (file)
@@ -5,7 +5,7 @@ import pytest
 
 from httpx import (
     URL,
-    Client,
+    AsyncClient,
     NotRedirectResponse,
     RedirectBodyUnavailable,
     RedirectLoop,
@@ -105,7 +105,7 @@ class MockDispatch(Dispatcher):
 
 @pytest.mark.usefixtures("async_environment")
 async def test_no_redirect():
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     url = "https://example.com/no_redirect"
     response = await client.get(url)
     assert response.status_code == 200
@@ -115,7 +115,7 @@ async def test_no_redirect():
 
 @pytest.mark.usefixtures("async_environment")
 async def test_redirect_301():
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     response = await client.post("https://example.org/redirect_301")
     assert response.status_code == codes.OK
     assert response.url == URL("https://example.org/")
@@ -124,7 +124,7 @@ async def test_redirect_301():
 
 @pytest.mark.usefixtures("async_environment")
 async def test_redirect_302():
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     response = await client.post("https://example.org/redirect_302")
     assert response.status_code == codes.OK
     assert response.url == URL("https://example.org/")
@@ -133,7 +133,7 @@ async def test_redirect_302():
 
 @pytest.mark.usefixtures("async_environment")
 async def test_redirect_303():
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     response = await client.get("https://example.org/redirect_303")
     assert response.status_code == codes.OK
     assert response.url == URL("https://example.org/")
@@ -142,7 +142,7 @@ async def test_redirect_303():
 
 @pytest.mark.usefixtures("async_environment")
 async def test_disallow_redirects():
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     response = await client.post(
         "https://example.org/redirect_303", allow_redirects=False
     )
@@ -160,7 +160,7 @@ async def test_disallow_redirects():
 
 @pytest.mark.usefixtures("async_environment")
 async def test_relative_redirect():
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     response = await client.get("https://example.org/relative_redirect")
     assert response.status_code == codes.OK
     assert response.url == URL("https://example.org/")
@@ -169,7 +169,7 @@ async def test_relative_redirect():
 
 @pytest.mark.usefixtures("async_environment")
 async def test_no_scheme_redirect():
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     response = await client.get("https://example.org/no_scheme_redirect")
     assert response.status_code == codes.OK
     assert response.url == URL("https://example.org/")
@@ -178,7 +178,7 @@ async def test_no_scheme_redirect():
 
 @pytest.mark.usefixtures("async_environment")
 async def test_fragment_redirect():
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     response = await client.get("https://example.org/relative_redirect#fragment")
     assert response.status_code == codes.OK
     assert response.url == URL("https://example.org/#fragment")
@@ -187,7 +187,7 @@ async def test_fragment_redirect():
 
 @pytest.mark.usefixtures("async_environment")
 async def test_multiple_redirects():
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     response = await client.get("https://example.org/multiple_redirects?count=20")
     assert response.status_code == codes.OK
     assert response.url == URL("https://example.org/multiple_redirects")
@@ -204,14 +204,14 @@ async def test_multiple_redirects():
 
 @pytest.mark.usefixtures("async_environment")
 async def test_too_many_redirects():
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     with pytest.raises(TooManyRedirects):
         await client.get("https://example.org/multiple_redirects?count=21")
 
 
 @pytest.mark.usefixtures("async_environment")
 async def test_too_many_redirects_calling_next():
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     url = "https://example.org/multiple_redirects?count=21"
     response = await client.get(url, allow_redirects=False)
     with pytest.raises(TooManyRedirects):
@@ -221,14 +221,14 @@ async def test_too_many_redirects_calling_next():
 
 @pytest.mark.usefixtures("async_environment")
 async def test_redirect_loop():
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     with pytest.raises(RedirectLoop):
         await client.get("https://example.org/redirect_loop")
 
 
 @pytest.mark.usefixtures("async_environment")
 async def test_redirect_loop_calling_next():
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     url = "https://example.org/redirect_loop"
     response = await client.get(url, allow_redirects=False)
     with pytest.raises(RedirectLoop):
@@ -238,7 +238,7 @@ async def test_redirect_loop_calling_next():
 
 @pytest.mark.usefixtures("async_environment")
 async def test_cross_domain_redirect():
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     url = "https://example.com/cross_domain"
     headers = {"Authorization": "abc"}
     response = await client.get(url, headers=headers)
@@ -248,7 +248,7 @@ async def test_cross_domain_redirect():
 
 @pytest.mark.usefixtures("async_environment")
 async def test_same_domain_redirect():
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     url = "https://example.org/cross_domain"
     headers = {"Authorization": "abc"}
     response = await client.get(url, headers=headers)
@@ -261,7 +261,7 @@ async def test_body_redirect():
     """
     A 308 redirect should preserve the request body.
     """
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     url = "https://example.org/redirect_body"
     data = b"Example request body"
     response = await client.post(url, data=data)
@@ -275,7 +275,7 @@ async def test_no_body_redirect():
     """
     A 303 redirect should remove the request body.
     """
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     url = "https://example.org/redirect_no_body"
     data = b"Example request body"
     response = await client.post(url, data=data)
@@ -286,7 +286,7 @@ async def test_no_body_redirect():
 
 @pytest.mark.usefixtures("async_environment")
 async def test_cannot_redirect_streaming_body():
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     url = "https://example.org/redirect_body"
 
     async def streaming_body():
@@ -298,7 +298,7 @@ async def test_cannot_redirect_streaming_body():
 
 @pytest.mark.usefixtures("async_environment")
 async def test_cross_subdomain_redirect():
-    client = Client(dispatch=MockDispatch())
+    client = AsyncClient(dispatch=MockDispatch())
     url = "https://example.com/cross_subdomain"
     response = await client.get(url)
     assert response.url == URL("https://www.example.org/cross_subdomain")
@@ -345,7 +345,7 @@ class MockCookieDispatch(Dispatcher):
 
 @pytest.mark.usefixtures("async_environment")
 async def test_redirect_cookie_behavior():
-    client = Client(dispatch=MockCookieDispatch())
+    client = AsyncClient(dispatch=MockCookieDispatch())
 
     # The client is not logged in.
     response = await client.get("https://example.com/")
index 72c227fef4b09f4b9bf1853e7c917439bf339b96..09e5953c9d881bf57690673db08fca95a0ef5c93 100644 (file)
@@ -6,7 +6,7 @@ import h2.events
 import pytest
 from h2.settings import SettingCodes
 
-from httpx import Client, Response, TimeoutException
+from httpx import AsyncClient, Response, TimeoutException
 
 from .utils import MockHTTP2Backend
 
@@ -26,7 +26,7 @@ async def app(request):
 async def test_http2_get_request():
     backend = MockHTTP2Backend(app=app)
 
-    async with Client(backend=backend, http2=True) as client:
+    async with AsyncClient(backend=backend, http2=True) as client:
         response = await client.get("http://example.org")
 
     assert response.status_code == 200
@@ -37,7 +37,7 @@ async def test_http2_get_request():
 async def test_http2_post_request():
     backend = MockHTTP2Backend(app=app)
 
-    async with Client(backend=backend, http2=True) as client:
+    async with AsyncClient(backend=backend, http2=True) as client:
         response = await client.post("http://example.org", data=b"<data>")
 
     assert response.status_code == 200
@@ -53,7 +53,7 @@ async def test_http2_large_post_request():
     backend = MockHTTP2Backend(app=app)
 
     data = b"a" * 100000
-    async with Client(backend=backend, http2=True) as client:
+    async with AsyncClient(backend=backend, http2=True) as client:
         response = await client.post("http://example.org", data=data)
     assert response.status_code == 200
     assert json.loads(response.content) == {
@@ -67,7 +67,7 @@ async def test_http2_large_post_request():
 async def test_http2_multiple_requests():
     backend = MockHTTP2Backend(app=app)
 
-    async with Client(backend=backend, http2=True) as client:
+    async with AsyncClient(backend=backend, http2=True) as client:
         response_1 = await client.get("http://example.org/1")
         response_2 = await client.get("http://example.org/2")
         response_3 = await client.get("http://example.org/3")
@@ -90,7 +90,7 @@ async def test_http2_reconnect():
     """
     backend = MockHTTP2Backend(app=app)
 
-    async with Client(backend=backend, http2=True) as client:
+    async with AsyncClient(backend=backend, http2=True) as client:
         response_1 = await client.get("http://example.org/1")
         backend.server.close_connection = True
         response_2 = await client.get("http://example.org/2")
@@ -106,7 +106,7 @@ async def test_http2_reconnect():
 async def test_http2_settings_in_handshake():
     backend = MockHTTP2Backend(app=app)
 
-    async with Client(backend=backend, http2=True) as client:
+    async with AsyncClient(backend=backend, http2=True) as client:
         await client.get("http://example.org")
 
     h2_conn = backend.server.conn
@@ -140,7 +140,7 @@ async def test_http2_settings_in_handshake():
 
 @pytest.mark.usefixtures("async_environment")
 async def test_http2_live_request():
-    async with Client(http2=True) as client:
+    async with AsyncClient(http2=True) as client:
         try:
             resp = await client.get("https://nghttp2.org/httpbin/anything")
         except TimeoutException:
index 3ae1968c4a111788e969ec0e132bf28bd87154bc..2b40586288e13c7c7fbf5199c6b2fd48b55e36e7 100644 (file)
@@ -41,7 +41,7 @@ async def raise_exc_after_response(scope, receive, send):
 
 @pytest.mark.asyncio
 async def test_asgi():
-    client = httpx.Client(app=hello_world)
+    client = httpx.AsyncClient(app=hello_world)
     response = await client.get("http://www.example.org/")
     assert response.status_code == 200
     assert response.text == "Hello, World!"
@@ -49,7 +49,7 @@ async def test_asgi():
 
 @pytest.mark.asyncio
 async def test_asgi_upload():
-    client = httpx.Client(app=echo_body)
+    client = httpx.AsyncClient(app=echo_body)
     response = await client.post("http://www.example.org/", data=b"example")
     assert response.status_code == 200
     assert response.text == "example"
@@ -57,13 +57,13 @@ async def test_asgi_upload():
 
 @pytest.mark.asyncio
 async def test_asgi_exc():
-    client = httpx.Client(app=raise_exc)
+    client = httpx.AsyncClient(app=raise_exc)
     with pytest.raises(ValueError):
         await client.get("http://www.example.org/")
 
 
 @pytest.mark.asyncio
 async def test_asgi_exc_after_response():
-    client = httpx.Client(app=raise_exc_after_response)
+    client = httpx.AsyncClient(app=raise_exc_after_response)
     with pytest.raises(ValueError):
         await client.get("http://www.example.org/")
index fb7618cb60255f1bd22e1f0d13c908989627d092..eb1eaac41abc3a6aa4ab23772d3062e3100db59a 100644 (file)
@@ -28,7 +28,7 @@ class MockDispatch(Dispatcher):
 @pytest.mark.parametrize(("value,output"), (("abc", b"abc"), (b"abc", b"abc")))
 @pytest.mark.asyncio
 async def test_multipart(value, output):
-    client = httpx.Client(dispatch=MockDispatch())
+    client = httpx.AsyncClient(dispatch=MockDispatch())
 
     # Test with a single-value 'data' argument, and a plain file 'files' argument.
     data = {"text": value}
@@ -52,7 +52,7 @@ async def test_multipart(value, output):
 @pytest.mark.parametrize(("key"), (b"abc", 1, 2.3, None))
 @pytest.mark.asyncio
 async def test_multipart_invalid_key(key):
-    client = httpx.Client(dispatch=MockDispatch())
+    client = httpx.AsyncClient(dispatch=MockDispatch())
     data = {key: "abc"}
     files = {"file": io.BytesIO(b"<file content>")}
     with pytest.raises(TypeError) as e:
@@ -63,7 +63,7 @@ async def test_multipart_invalid_key(key):
 @pytest.mark.parametrize(("value"), (1, 2.3, None, [None, "abc"], {None: "abc"}))
 @pytest.mark.asyncio
 async def test_multipart_invalid_value(value):
-    client = httpx.Client(dispatch=MockDispatch())
+    client = httpx.AsyncClient(dispatch=MockDispatch())
     data = {"text": value}
     files = {"file": io.BytesIO(b"<file content>")}
     with pytest.raises(TypeError) as e:
@@ -73,7 +73,7 @@ async def test_multipart_invalid_value(value):
 
 @pytest.mark.asyncio
 async def test_multipart_file_tuple():
-    client = httpx.Client(dispatch=MockDispatch())
+    client = httpx.AsyncClient(dispatch=MockDispatch())
 
     # Test with a list of values 'data' argument, and a tuple style 'files' argument.
     data = {"text": ["abc"]}
index 0cee4af8a7f2d9ea7106c1629892efc09ac29f88..e394e0e301e783738ab8a30130dbcbf51e38bc47 100644 (file)
@@ -7,7 +7,7 @@ import httpx
 async def test_read_timeout(server):
     timeout = httpx.Timeout(read_timeout=1e-6)
 
-    async with httpx.Client(timeout=timeout) as client:
+    async with httpx.AsyncClient(timeout=timeout) as client:
         with pytest.raises(httpx.ReadTimeout):
             await client.get(server.url.copy_with(path="/slow_response"))
 
@@ -16,7 +16,7 @@ async def test_read_timeout(server):
 async def test_write_timeout(server):
     timeout = httpx.Timeout(write_timeout=1e-6)
 
-    async with httpx.Client(timeout=timeout) as client:
+    async with httpx.AsyncClient(timeout=timeout) as client:
         with pytest.raises(httpx.WriteTimeout):
             data = b"*" * 1024 * 1024 * 100
             await client.put(server.url.copy_with(path="/slow_response"), data=data)
@@ -26,7 +26,7 @@ async def test_write_timeout(server):
 async def test_connect_timeout(server):
     timeout = httpx.Timeout(connect_timeout=1e-6)
 
-    async with httpx.Client(timeout=timeout) as client:
+    async with httpx.AsyncClient(timeout=timeout) as client:
         with pytest.raises(httpx.ConnectTimeout):
             # See https://stackoverflow.com/questions/100841/
             await client.get("http://10.255.255.1/")
@@ -37,7 +37,7 @@ async def test_pool_timeout(server):
     pool_limits = httpx.PoolLimits(hard_limit=1)
     timeout = httpx.Timeout(pool_timeout=1e-4)
 
-    async with httpx.Client(pool_limits=pool_limits, timeout=timeout) as client:
+    async with httpx.AsyncClient(pool_limits=pool_limits, timeout=timeout) as client:
         async with client.stream("GET", server.url):
             with pytest.raises(httpx.PoolTimeout):
                 await client.get("http://localhost:8000/")
index c1cf93fa8585bd7f37659320bf8c4d2c6e0f9538..c062801650f65a2593c1b579d0ab68871d990c79 100644 (file)
@@ -93,7 +93,7 @@ def test_parse_header_links(value, expected):
 @pytest.mark.asyncio
 async def test_logs_debug(server, capsys):
     with override_log_level("debug"):
-        async with httpx.Client() as client:
+        async with httpx.AsyncClient() as client:
             response = await client.get(server.url)
             assert response.status_code == 200
     stderr = capsys.readouterr().err
@@ -104,7 +104,7 @@ async def test_logs_debug(server, capsys):
 @pytest.mark.asyncio
 async def test_logs_trace(server, capsys):
     with override_log_level("trace"):
-        async with httpx.Client() as client:
+        async with httpx.AsyncClient() as client:
             response = await client.get(server.url)
             assert response.status_code == 200
     stderr = capsys.readouterr().err
@@ -115,7 +115,7 @@ async def test_logs_trace(server, capsys):
 @pytest.mark.asyncio
 async def test_logs_redirect_chain(server, capsys):
     with override_log_level("debug"):
-        async with httpx.Client() as client:
+        async with httpx.AsyncClient() as client:
             response = await client.get(server.url.copy_with(path="/redirect_301"))
             assert response.status_code == 200