Skip to content

Commit

Permalink
NetRC lookups should use host, not host+port (#1298)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchristie committed Sep 18, 2020
1 parent 354c4ca commit ed27682
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion httpx/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def _build_request_auth(
return BasicAuth(username=username, password=password)

if self.trust_env and "Authorization" not in request.headers:
credentials = self._netrc.get_credentials(request.url.authority)
credentials = self._netrc.get_credentials(request.url.host)
if credentials is not None:
return BasicAuth(username=credentials[0], password=credentials[1])

Expand Down
6 changes: 2 additions & 4 deletions httpx/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,11 @@ def netrc_info(self) -> typing.Optional[netrc.netrc]:
pass
return self._netrc_info

def get_credentials(
self, authority: str
) -> typing.Optional[typing.Tuple[str, str]]:
def get_credentials(self, host: str) -> typing.Optional[typing.Tuple[str, str]]:
if self.netrc_info is None:
return None

auth_info = self.netrc_info.authenticators(authority)
auth_info = self.netrc_info.authenticators(host)
if auth_info is None or auth_info[2] is None:
return None
return (auth_info[0], auth_info[2])
Expand Down

0 comments on commit ed27682

Please sign in to comment.