Skip to content

Commit

Permalink
Merge pull request #6028 from nateprewitt/prox_auth_fix
Browse files Browse the repository at this point in the history
Fix auth parsing for proxies
  • Loading branch information
sigmavirus24 committed Jan 4, 2022
2 parents 0192aac + 38f3f8e commit 8fa9724
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions requests/utils.py
Expand Up @@ -974,6 +974,10 @@ def prepend_scheme_if_needed(url, new_scheme):
if not netloc:
netloc, path = path, netloc

if auth:
# parse_url doesn't provide the netloc with auth
# so we'll add it ourselves.
netloc = '@'.join([auth, netloc])
if scheme is None:
scheme = new_scheme
if path is None:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_utils.py
Expand Up @@ -602,6 +602,14 @@ def test_parse_header_links(value, expected):
('example.com/path', 'http://example.com/path'),
('//example.com/path', 'http://example.com/path'),
('example.com:80', 'http://example.com:80'),
(
'http://user:pass@example.com/path?query',
'http://user:pass@example.com/path?query'
),
(
'http://user@example.com/path?query',
'http://user@example.com/path?query'
)
))
def test_prepend_scheme_if_needed(value, expected):
assert prepend_scheme_if_needed(value, 'http') == expected
Expand Down

0 comments on commit 8fa9724

Please sign in to comment.