-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
NO_PROXY
environment variable can be used to override `HTTP(S…
…)_PROXY` values (#301) When determining if a proxy should be used, the SDK would: 1. Check the `config.http_config.http_proxy` value. If that is set, use that value without further consideration. 2. If the target URI is `https`, use the value from the `HTTPS_PROXY` environment variable. 3. If the target is `http`, use `HTTP_PROXY` instead. The SDK will now support another environment variable -- `NO_PROXY`. This variable can be set to a comma-separated list of hosts to exclude from proxy support, or the special case '*' meaning to ignore all hosts. The `NO_PROXY` variable will only take affect if the SDK isn't explicitly configured to use a proxy as specified in #1 above.
- Loading branch information
Showing
3 changed files
with
132 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import pytest | ||
|
||
from typing import Optional | ||
from ldclient.impl.http import _get_proxy_url | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'target_uri, no_proxy, expected', | ||
[ | ||
('https://secure.example.com', '', 'https://secure.proxy:1234'), | ||
('http://insecure.example.com', '', 'http://insecure.proxy:6789'), | ||
('https://secure.example.com', 'secure.example.com', None), | ||
('https://secure.example.com', 'secure.example.com:443', None), | ||
('https://secure.example.com', 'secure.example.com:80', 'https://secure.proxy:1234'), | ||
('https://secure.example.com', 'wrong.example.com', 'https://secure.proxy:1234'), | ||
('https://secure.example.com:8080', 'secure.example.com', None), | ||
('https://secure.example.com:8080', 'secure.example.com:443', 'https://secure.proxy:1234'), | ||
('https://secure.example.com', 'example.com', None), | ||
('https://secure.example.com', 'example.com:443', None), | ||
('https://secure.example.com', 'example.com:80', 'https://secure.proxy:1234'), | ||
('http://insecure.example.com', 'insecure.example.com', None), | ||
('http://insecure.example.com', 'insecure.example.com:443', 'http://insecure.proxy:6789'), | ||
('http://insecure.example.com', 'insecure.example.com:80', None), | ||
('http://insecure.example.com', 'wrong.example.com', 'http://insecure.proxy:6789'), | ||
('http://insecure.example.com:8080', 'secure.example.com', None), | ||
('http://insecure.example.com:8080', 'secure.example.com:443', 'http://insecure.proxy:6789'), | ||
('http://insecure.example.com', 'example.com', None), | ||
('http://insecure.example.com', 'example.com:443', 'http://insecure.proxy:6789'), | ||
('http://insecure.example.com', 'example.com:80', None), | ||
('secure.example.com', 'secure.example.com', None), | ||
('secure.example.com', 'secure.example.com:443', 'http://insecure.proxy:6789'), | ||
('secure.example.com', 'secure.example.com:80', None), | ||
('secure.example.com', 'wrong.example.com', 'http://insecure.proxy:6789'), | ||
('secure.example.com:8080', 'secure.example.com', None), | ||
('secure.example.com:8080', 'secure.example.com:80', 'http://insecure.proxy:6789'), | ||
('https://secure.example.com', '*', None), | ||
('https://secure.example.com:8080', '*', None), | ||
('http://insecure.example.com', '*', None), | ||
('http://insecure.example.com:8080', '*', None), | ||
('secure.example.com:443', '*', None), | ||
('insecure.example.com:8080', '*', None), | ||
] | ||
) | ||
def test_honors_no_proxy(target_uri: str, no_proxy: str, expected: Optional[str], monkeypatch): | ||
monkeypatch.setenv('https_proxy', 'https://secure.proxy:1234') | ||
monkeypatch.setenv('http_proxy', 'http://insecure.proxy:6789') | ||
monkeypatch.setenv('no_proxy', no_proxy) | ||
|
||
proxy_url = _get_proxy_url(target_uri) | ||
|
||
assert proxy_url == expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters