]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Fix stream unsetting auth (#1312)
authorTom Christie <tom@tomchristie.com>
Wed, 23 Sep 2020 10:25:54 +0000 (11:25 +0100)
committerGitHub <noreply@github.com>
Wed, 23 Sep 2020 10:25:54 +0000 (11:25 +0100)
* Fix ASGITransport path escaping

* Add failing test case for auth with streaming

* Fix .stream setting auth=None

httpx/_client.py
tests/client/test_auth.py

index 6208535f0bd7b736e5bc462f75fc22dbe0256fc9..4661b221c526fb3a69f40f2f2b4a7466a82a6d7e 100644 (file)
@@ -234,7 +234,7 @@ class BaseClient:
         params: QueryParamTypes = None,
         headers: HeaderTypes = None,
         cookies: CookieTypes = None,
-        auth: AuthTypes = None,
+        auth: typing.Union[AuthTypes, UnsetType] = UNSET,
         allow_redirects: bool = True,
         timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET,
     ) -> "StreamContextManager":
@@ -1786,7 +1786,7 @@ class StreamContextManager:
         client: BaseClient,
         request: Request,
         *,
-        auth: AuthTypes = None,
+        auth: typing.Union[AuthTypes, UnsetType] = UNSET,
         allow_redirects: bool = True,
         timeout: typing.Union[TimeoutTypes, UnsetType] = UNSET,
         close_client: bool = False,
index e3d328c6fa9cc32b5267f78dcb6efa0adc2adfcc..efbfcc36c43f8836ecd5a9e52e815ac144994ed8 100644 (file)
@@ -162,6 +162,23 @@ async def test_basic_auth() -> None:
     assert response.json() == {"auth": "Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM="}
 
 
+@pytest.mark.asyncio
+async def test_basic_auth_with_stream() -> None:
+    """
+    See: https://github.com/encode/httpx/pull/1312
+    """
+    url = "https://example.org/"
+    auth = ("tomchristie", "password123")
+    app = App()
+
+    async with httpx.AsyncClient(transport=MockTransport(app), auth=auth) as client:
+        async with client.stream("GET", url) as response:
+            response.read()
+
+    assert response.status_code == 200
+    assert response.json() == {"auth": "Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM="}
+
+
 @pytest.mark.asyncio
 async def test_basic_auth_in_url() -> None:
     url = "https://tomchristie:password123@example.org/"