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

proxy: fix parser in non-authorization-case #206

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions python3/httplib2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,18 +929,19 @@ def proxy_info_from_environment(method="http"):
def proxy_info_from_url(url, method="http", noproxy=None):
"""Construct a ProxyInfo from a URL (such as http_proxy env var)
"""
url = urllib.parse.urlparse(url)
username = None
password = None
port = None
if "@" in url[1]:
ident, host_port = url[1].split("@", 1)
if "://" in url:
url = url.split("://")[1]
if "@" in url:
ident, host_port = url.split("@", 1)
if ":" in ident:
username, password = ident.split(":", 1)
else:
password = ident
else:
host_port = url[1]
host_port = url
if ":" in host_port:
host, port = host_port.split(":", 1)
else:
Expand Down
13 changes: 13 additions & 0 deletions tests/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ def test_from_url_ident():
assert pi.proxy_user == "zoidberg"
assert pi.proxy_pass == "fish"

def test_from_no_scheme_string():
pi = httplib2.proxy_info_from_url("zoidberg:fish@someproxy:99")
assert pi.proxy_host == "someproxy"
assert pi.proxy_port == 99
assert pi.proxy_user == "zoidberg"
assert pi.proxy_pass == "fish"

def test_from_no_scheme_host_only_string():
pi = httplib2.proxy_info_from_url("someproxy")
assert pi.proxy_host == "someproxy"
assert pi.proxy_port == 80
assert pi.proxy_user == None
assert pi.proxy_pass == None

def test_from_env(monkeypatch):
assert os.environ.get("http_proxy") is None
Expand Down