1
- import os
2
1
import json
3
2
import time
4
3
import zlib
15
14
logger = logging .getLogger (__name__ )
16
15
17
16
18
- def _make_pool ():
19
- proxy = os .environ .get ("HTTP_PROXY" )
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." )
24
+
20
25
opts = {"num_pools" : 2 , "cert_reqs" : "CERT_REQUIRED" , "ca_certs" : certifi .where ()}
21
- if proxy is not None :
22
- return urllib3 .ProxyManager (proxy , ** opts )
26
+
27
+ if https_proxy or http_proxy :
28
+ return urllib3 .ProxyManager (https_proxy or http_proxy , ** opts )
23
29
else :
24
30
return urllib3 .PoolManager (** opts )
25
31
26
32
27
33
_SHUTDOWN = object ()
28
- _pool = _make_pool ()
29
34
_retry = urllib3 .util .Retry ()
30
35
31
36
32
- def send_event (event , auth ):
37
+ def send_event (pool , event , auth ):
33
38
body = zlib .compress (json .dumps (event ).encode ("utf-8" ))
34
- response = _pool .request (
39
+ response = pool .request (
35
40
"POST" ,
36
41
auth .store_api_url ,
37
42
body = body ,
@@ -73,7 +78,7 @@ def thread():
73
78
break
74
79
75
80
try :
76
- disabled_until = send_event (item , auth )
81
+ disabled_until = send_event (transport . _pool , item , auth )
77
82
except Exception :
78
83
logger .exception ("Could not send sentry event" )
79
84
continue
@@ -84,10 +89,11 @@ def thread():
84
89
85
90
86
91
class Transport (object ):
87
- def __init__ (self , dsn ):
92
+ def __init__ (self , dsn , http_proxy , https_proxy ):
88
93
self .dsn = dsn
89
94
self ._queue = None
90
95
self ._done = False
96
+ self ._pool = _make_pool (http_proxy = http_proxy , https_proxy = https_proxy )
91
97
92
98
def start (self ):
93
99
if self ._queue is None :
0 commit comments