Skip to content

Commit 90e3c05

Browse files
committed
chore: actually implement http_proxy properly
1 parent 663c755 commit 90e3c05

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

sentry_sdk/consts.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
import socket
32

43
VERSION = "0.1"
@@ -17,8 +16,8 @@
1716
"transport": None,
1817
"sample_rate": 1.0,
1918
"send_default_pii": False,
20-
"http_proxy": os.environ.get("http_proxy"),
21-
"https_proxy": os.environ.get("https_proxy"),
19+
"http_proxy": None,
20+
"https_proxy": None,
2221
"ignore_errors": (),
2322
}
2423

sentry_sdk/transport.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,24 @@
1010
from ._compat import queue
1111
from .consts import VERSION
1212

13+
try:
14+
from urllib.request import getproxies
15+
except ImportError:
16+
from urllib import getproxies
17+
1318

1419
logger = logging.getLogger(__name__)
1520

1621

17-
def _make_pool(http_proxy, https_proxy):
18-
if https_proxy and http_proxy:
19-
raise ValueError("Either http_proxy or https_proxy can be set, not " "both.")
20-
elif https_proxy and not https_proxy.startswith("https://"):
21-
raise ValueError("https_proxy URL must have https scheme.")
22-
elif http_proxy and not http_proxy.startswith("http://"):
23-
raise ValueError("http_proxy URL must have http scheme.")
22+
def _make_pool(dsn, http_proxy, https_proxy):
23+
proxy = https_proxy if dsn == "https" else http_proxy
24+
if not proxy:
25+
proxy = getproxies().get(dsn.scheme)
2426

25-
opts = {"num_pools": 2, "cert_reqs": "CERT_REQUIRED", "ca_certs": certifi.where()}
27+
opts = {"num_pools": 2, "cert_reqs": "CERT_NONE", "ca_certs": certifi.where()}
2628

27-
if https_proxy or http_proxy:
28-
return urllib3.ProxyManager(https_proxy or http_proxy, **opts)
29+
if proxy:
30+
return urllib3.ProxyManager(proxy, **opts)
2931
else:
3032
return urllib3.PoolManager(**opts)
3133

@@ -93,7 +95,7 @@ def __init__(self, dsn, http_proxy=None, https_proxy=None):
9395
self.dsn = dsn
9496
self._queue = None
9597
self._done = False
96-
self._pool = _make_pool(http_proxy=http_proxy, https_proxy=https_proxy)
98+
self._pool = _make_pool(dsn, http_proxy=http_proxy, https_proxy=https_proxy)
9799

98100
def start(self):
99101
if self._queue is None:

tests/test_client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
from sentry_sdk import Client
3-
from sentry_sdk.utils import Event
3+
from sentry_sdk.utils import Event, Dsn
44
from sentry_sdk.transport import Transport
55

66

@@ -10,13 +10,13 @@ def test_transport_option(monkeypatch):
1010
assert str(Client(dsn=dsn).dsn) == dsn
1111
assert Client().dsn is None
1212
with pytest.raises(ValueError):
13-
Client(dsn, transport=Transport(dsn2))
13+
Client(dsn, transport=Transport(Dsn(dsn2)))
1414
with pytest.raises(ValueError):
15-
Client(dsn, transport=Transport(dsn))
16-
assert str(Client(transport=Transport(dsn2)).dsn) == dsn2
15+
Client(dsn, transport=Transport(Dsn(dsn)))
16+
assert str(Client(transport=Transport(Dsn(dsn2))).dsn) == dsn2
1717

1818
monkeypatch.setenv("SENTRY_DSN", dsn)
19-
assert str(Client(transport=Transport(dsn2)).dsn) == dsn2
19+
assert str(Client(transport=Transport(Dsn(dsn2))).dsn) == dsn2
2020

2121

2222
def test_ignore_errors():

0 commit comments

Comments
 (0)