Skip to content
Myr

Ensure Authorization header has priority over .netrc

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tom Christie · committed by Tom Christie · parent 8d55d78 · Browse files · 2 files+13 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+13 added−1 removed

  • tests:+12 added−0 removed
  • other:+1 added−1 removed

2 files+13 added−1 removed

modified:httpx/client.py+1 added-1 removed
382 unmodified lines
383 if username or password:384 auth = BasicAuth(username=username, password=password)385 return auth(request)386387 if trust_env:387 if trust_env and "Authorization" not in request.headers:388 credentials = self.netrc.get_credentials(request.url.authority)389 if credentials is not None:390 auth = BasicAuth(username=credentials[0], password=credentials[1])391 return auth(request)
479 unmodified lines
modified:tests/client/test_auth.py+12 added
155 unmodified lines
156 }157158159@pytest.mark.asyncio160async def test_auth_header_has_priority_over_netrc():161 os.environ["NETRC"] = "tests/.netrc"162 url = "http://netrcexample.org"163164 client = Client(dispatch=MockDispatch())165 response = await client.get(url, headers={"Authorization": "Override"})166167 assert response.status_code == 200168 assert response.json() == {"auth": "Override"}169170171@pytest.mark.asyncio172async def test_trust_env_auth():173 os.environ["NETRC"] = "tests/.netrc"174 url = "http://netrcexample.org"175
204 unmodified lines