Skip to content

Commit 58ec2e4

Browse files
committed
fix: Buggy proxy behavior
1 parent 4327066 commit 58ec2e4

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

sentry_sdk/transport.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020

2121
def _make_pool(parsed_dsn, http_proxy, https_proxy, ca_certs):
22-
proxy = https_proxy if parsed_dsn == "https" else http_proxy
22+
# Use http_proxy if scheme is https and https_proxy is not set
23+
proxy = parsed_dsn.scheme == "https" and https_proxy or http_proxy
2324
if not proxy:
2425
proxy = getproxies().get(parsed_dsn.scheme)
2526

tests/test_client.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,28 @@ def test_transport_option(monkeypatch):
3434
assert str(Client(transport=transport).dsn) == dsn
3535

3636

37+
def test_http_proxy(monkeypatch):
38+
client = Client("https://foo@sentry.io/123", http_proxy="http://localhost/123")
39+
assert client.transport._pool.proxy.scheme == "http"
40+
41+
client = Client(
42+
"https://foo@sentry.io/123",
43+
https_proxy="https://localhost/123",
44+
http_proxy="http://localhost/123",
45+
)
46+
assert client.transport._pool.proxy.scheme == "https"
47+
48+
client = Client("http://foo@sentry.io/123", http_proxy="http://localhost/123")
49+
assert client.transport._pool.proxy.scheme == "http"
50+
51+
client = Client(
52+
"http://foo@sentry.io/123",
53+
https_proxy="https://localhost/123",
54+
http_proxy="http://localhost/123",
55+
)
56+
assert client.transport._pool.proxy.scheme == "http"
57+
58+
3759
def test_simple_transport():
3860
events = []
3961
with Hub(Client(transport=events.append)):

0 commit comments

Comments
 (0)