Skip to content

Commit

Permalink
Expose proxy_headers as top level config and use in ProxyManager
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py committed Nov 17, 2022
1 parent 442e71c commit 3fb3fa0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def __init__(
auto_session_tracking=True, # type: bool
send_client_reports=True, # type: bool
_experiments={}, # type: Experiments # noqa: B006
proxy_headers=None, # type: Optional[Dict[str, str]]
):
# type: (...) -> None
pass
Expand Down
5 changes: 5 additions & 0 deletions sentry_sdk/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def __init__(
http_proxy=options["http_proxy"],
https_proxy=options["https_proxy"],
ca_certs=options["ca_certs"],
proxy_headers=options["proxy_headers"],
)

from sentry_sdk import Hub
Expand Down Expand Up @@ -420,6 +421,7 @@ def _make_pool(
http_proxy, # type: Optional[str]
https_proxy, # type: Optional[str]
ca_certs, # type: Optional[Any]
proxy_headers, # type: Optional[Dict[str, str]]
):
# type: (...) -> Union[PoolManager, ProxyManager]
proxy = None
Expand All @@ -436,6 +438,9 @@ def _make_pool(
opts = self._get_pool_options(ca_certs)

if proxy:
if proxy_headers:
opts["proxy_headers"] = proxy_headers

return urllib3.ProxyManager(proxy, **opts)
else:
return urllib3.PoolManager(**opts)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ def test_transport_option(monkeypatch):
"arg_https_proxy": "https://localhost/123",
"expected_proxy_scheme": "https",
},
{
"dsn": "https://[email protected]/123",
"env_http_proxy": None,
"env_https_proxy": None,
"env_no_proxy": "sentry.io,example.com",
"arg_http_proxy": None,
"arg_https_proxy": "https://localhost/123",
"expected_proxy_scheme": "https",
"arg_proxy_headers": {"Test-Header": "foo-bar"},
},
],
)
def test_proxy(monkeypatch, testcase):
Expand All @@ -241,12 +251,17 @@ def test_proxy(monkeypatch, testcase):
kwargs["http_proxy"] = testcase["arg_http_proxy"]
if testcase["arg_https_proxy"] is not None:
kwargs["https_proxy"] = testcase["arg_https_proxy"]
if testcase.get("arg_proxy_headers") is not None:
kwargs["proxy_headers"] = testcase["arg_proxy_headers"]
client = Client(testcase["dsn"], **kwargs)
if testcase["expected_proxy_scheme"] is None:
assert client.transport._pool.proxy is None
else:
assert client.transport._pool.proxy.scheme == testcase["expected_proxy_scheme"]

if testcase.get("arg_proxy_headers") is not None:
assert client.transport._pool.proxy_headers == testcase["arg_proxy_headers"]


def test_simple_transport(sentry_init):
events = []
Expand Down

0 comments on commit 3fb3fa0

Please sign in to comment.