Skip to content

Commit bd99d4e

Browse files
authored
Expose proxy_headers as top level config and use in ProxyManager (#1746)
1 parent 442e71c commit bd99d4e

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

sentry_sdk/consts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def __init__(
8181
auto_session_tracking=True, # type: bool
8282
send_client_reports=True, # type: bool
8383
_experiments={}, # type: Experiments # noqa: B006
84+
proxy_headers=None, # type: Optional[Dict[str, str]]
8485
):
8586
# type: (...) -> None
8687
pass

sentry_sdk/transport.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ def __init__(
156156
http_proxy=options["http_proxy"],
157157
https_proxy=options["https_proxy"],
158158
ca_certs=options["ca_certs"],
159+
proxy_headers=options["proxy_headers"],
159160
)
160161

161162
from sentry_sdk import Hub
@@ -420,6 +421,7 @@ def _make_pool(
420421
http_proxy, # type: Optional[str]
421422
https_proxy, # type: Optional[str]
422423
ca_certs, # type: Optional[Any]
424+
proxy_headers, # type: Optional[Dict[str, str]]
423425
):
424426
# type: (...) -> Union[PoolManager, ProxyManager]
425427
proxy = None
@@ -436,6 +438,9 @@ def _make_pool(
436438
opts = self._get_pool_options(ca_certs)
437439

438440
if proxy:
441+
if proxy_headers:
442+
opts["proxy_headers"] = proxy_headers
443+
439444
return urllib3.ProxyManager(proxy, **opts)
440445
else:
441446
return urllib3.PoolManager(**opts)

tests/test_client.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,16 @@ def test_transport_option(monkeypatch):
227227
"arg_https_proxy": "https://localhost/123",
228228
"expected_proxy_scheme": "https",
229229
},
230+
{
231+
"dsn": "https://foo@sentry.io/123",
232+
"env_http_proxy": None,
233+
"env_https_proxy": None,
234+
"env_no_proxy": "sentry.io,example.com",
235+
"arg_http_proxy": None,
236+
"arg_https_proxy": "https://localhost/123",
237+
"expected_proxy_scheme": "https",
238+
"arg_proxy_headers": {"Test-Header": "foo-bar"},
239+
},
230240
],
231241
)
232242
def test_proxy(monkeypatch, testcase):
@@ -241,12 +251,17 @@ def test_proxy(monkeypatch, testcase):
241251
kwargs["http_proxy"] = testcase["arg_http_proxy"]
242252
if testcase["arg_https_proxy"] is not None:
243253
kwargs["https_proxy"] = testcase["arg_https_proxy"]
254+
if testcase.get("arg_proxy_headers") is not None:
255+
kwargs["proxy_headers"] = testcase["arg_proxy_headers"]
244256
client = Client(testcase["dsn"], **kwargs)
245257
if testcase["expected_proxy_scheme"] is None:
246258
assert client.transport._pool.proxy is None
247259
else:
248260
assert client.transport._pool.proxy.scheme == testcase["expected_proxy_scheme"]
249261

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

251266
def test_simple_transport(sentry_init):
252267
events = []

0 commit comments

Comments
 (0)