From 38f3f8ecb93cadfac03a6b7b3173018ac829d0cf Mon Sep 17 00:00:00 2001 From: Nate Prewitt Date: Tue, 4 Jan 2022 08:26:59 -0700 Subject: [PATCH] Fix auth parsing for proxies Co-authored-by: adamp01 <@adamp01> --- requests/utils.py | 4 ++++ tests/test_utils.py | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/requests/utils.py b/requests/utils.py index 1c2ae4e0eb..153776c7f3 100644 --- a/requests/utils.py +++ b/requests/utils.py @@ -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: diff --git a/tests/test_utils.py b/tests/test_utils.py index c2186b885f..8e98397204 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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