Skip to content

Commit

Permalink
pac_context_for_url(): Don't set None for proxy env vars.
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonyl committed Aug 26, 2018
1 parent 8350791 commit fa92c09
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pypac/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,9 @@ def pac_context_for_url(url, proxy_auth=None):
if pac:
resolver = ProxyResolver(pac, proxy_auth=proxy_auth)
proxies = resolver.get_proxy_for_requests(url)
os.environ['HTTP_PROXY'] = proxies.get('http')
os.environ['HTTPS_PROXY'] = proxies.get('https')
# Cannot set None for environ. (#27)
os.environ['HTTP_PROXY'] = proxies.get('http') or ''
os.environ['HTTPS_PROXY'] = proxies.get('https') or ''
yield
if prev_http_proxy:
os.environ['HTTP_PROXY'] = prev_http_proxy
Expand Down
8 changes: 8 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,11 @@ def test_pac(self, monkeypatch):
assert os.environ['HTTP_PROXY'] == fake_proxy_url
assert os.environ['HTTPS_PROXY'] == fake_proxy_url
assert os.environ['HTTP_PROXY'] == 'http://env'

def test_pac_direct(self, monkeypatch):
monkeypatch.setenv('HTTP_PROXY', 'http://env')
with _patch_get_pac(PACFile(proxy_pac_js_tpl % 'DIRECT')):
with pac_context_for_url(arbitrary_url):
assert os.environ['HTTP_PROXY'] == ''
assert os.environ['HTTPS_PROXY'] == ''
assert os.environ['HTTP_PROXY'] == 'http://env'

0 comments on commit fa92c09

Please sign in to comment.