Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NetRC lookups should use host, not host+port #1298

Merged
merged 1 commit into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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