Repository: encode/httpx

Issue:
auth doesn't seem to be used in Client.stream
### Checklist

<!-- Please make sure you check all these items before submitting your bug report. -->

- [x] The bug is reproducible against the latest release: 0.14.3.
- [x] There are no similar issues or pull requests to fix it yet: that I could find....

### Describe the bug

Client.stream seems to not use auth as provided in the initializer of Client objects.

### To reproduce

1. Create an httpx.Client object with auth set.

`cli = httpx.Client(auth=("user", "password"))`

2. Check that the client.get/post works ok.

```
url = "<url to smallish file>"
resp = cli.get(url)
resp.raise_for_status()  # no error is raised
```

3. Then try Client.stream normally.
```
    with cli.stream("GET", url) as resp:
        resp.raise_for_status()  # HTTPStatusError 401 is raised
        ....
```

4. Try Client.stream with auth.
```
    with cli.stream("GET", url, auth=cli.auth) as resp:
        resp.raise_for_status()  # no error is raised
        ....
```


### Expected behavior

auth is used by method Client.stream.

### Actual behavior

auth is not used by method Client.stream.

### Environment

- OS:
- Python version
- HTTPX version:
```
Python 3.7.7 (default, May 16 2020, 11:38:23) 
[GCC 10.1.1 20200507 (Red Hat 10.1.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import httpx
>>> httpx.__version__
'0.14.3'
>>> 
```

- Async environment: sync
- HTTP proxy: no
- Custom certificates: no




Discussion:
Hmm — not able to reproduce…

```python
import httpx

client = httpx.Client(auth=("user", "pass"))

with client.stream("GET", "https://httpbin.org/basic-auth/user/pass") as r:
    print(r)  # <Response [200 OK]>

with client.stream("GET", "https://httpbin.org/basic-auth/user/otherpass") as r:
    print(r)  # <Response [401 Unauthorized]> (as expected)
```

Does the above^ reproduce the issue on your side? If not, what is the host you're requesting exactly? Could be a faulty server implementation… 🤔 

Resolving patch:
diff --git a/httpx/_client.py b/httpx/_client.py
--- a/httpx/_client.py
+++ b/httpx/_client.py
@@ -234,7 +234,7 @@ def stream(
         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 @@ def __init__(
         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,


Test patch:
diff --git a/tests/client/test_auth.py b/tests/client/test_auth.py
--- a/tests/client/test_auth.py
+++ b/tests/client/test_auth.py
@@ -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/"