@@ -215,15 +215,7 @@ def __init__(self, options):
215
215
) # type: DefaultDict[Tuple[EventDataCategory, str], int]
216
216
self ._last_client_report_sent = time .time ()
217
217
218
- self ._pool = self ._make_pool (
219
- self .parsed_dsn ,
220
- http_proxy = options ["http_proxy" ],
221
- https_proxy = options ["https_proxy" ],
222
- ca_certs = options ["ca_certs" ],
223
- cert_file = options ["cert_file" ],
224
- key_file = options ["key_file" ],
225
- proxy_headers = options ["proxy_headers" ],
226
- )
218
+ self ._pool = self ._make_pool ()
227
219
228
220
# Backwards compatibility for deprecated `self.hub_class` attribute
229
221
self ._hub_cls = sentry_sdk .Hub
@@ -532,8 +524,8 @@ def _serialize_envelope(self, envelope):
532
524
533
525
return content_encoding , body
534
526
535
- def _get_pool_options (self , ca_certs , cert_file = None , key_file = None ):
536
- # type: (Self, Optional[Any], Optional[Any], Optional[Any] ) -> Dict[str, Any]
527
+ def _get_pool_options (self ):
528
+ # type: (Self) -> Dict[str, Any]
537
529
raise NotImplementedError ()
538
530
539
531
def _in_no_proxy (self , parsed_dsn ):
@@ -547,17 +539,8 @@ def _in_no_proxy(self, parsed_dsn):
547
539
return True
548
540
return False
549
541
550
- def _make_pool (
551
- self ,
552
- parsed_dsn , # type: Dsn
553
- http_proxy , # type: Optional[str]
554
- https_proxy , # type: Optional[str]
555
- ca_certs , # type: Optional[Any]
556
- cert_file , # type: Optional[Any]
557
- key_file , # type: Optional[Any]
558
- proxy_headers , # type: Optional[Dict[str, str]]
559
- ):
560
- # type: (...) -> Union[PoolManager, ProxyManager, httpcore.SOCKSProxy, httpcore.HTTPProxy, httpcore.ConnectionPool]
542
+ def _make_pool (self ):
543
+ # type: (Self) -> Union[PoolManager, ProxyManager, httpcore.SOCKSProxy, httpcore.HTTPProxy, httpcore.ConnectionPool]
561
544
raise NotImplementedError ()
562
545
563
546
def _request (
@@ -631,8 +614,8 @@ class HttpTransport(BaseHttpTransport):
631
614
if TYPE_CHECKING :
632
615
_pool : Union [PoolManager , ProxyManager ]
633
616
634
- def _get_pool_options (self , ca_certs , cert_file = None , key_file = None ):
635
- # type: (Self, Any, Any, Any ) -> Dict[str, Any]
617
+ def _get_pool_options (self ):
618
+ # type: (Self) -> Dict[str, Any]
636
619
637
620
num_pools = self .options .get ("_experiments" , {}).get ("transport_num_pools" )
638
621
options = {
@@ -658,42 +641,43 @@ def _get_pool_options(self, ca_certs, cert_file=None, key_file=None):
658
641
options ["socket_options" ] = socket_options
659
642
660
643
options ["ca_certs" ] = (
661
- ca_certs # User-provided bundle from the SDK init
644
+ self . options [ " ca_certs" ] # User-provided bundle from the SDK init
662
645
or os .environ .get ("SSL_CERT_FILE" )
663
646
or os .environ .get ("REQUESTS_CA_BUNDLE" )
664
647
or certifi .where ()
665
648
)
666
649
667
- options ["cert_file" ] = cert_file or os .environ .get ("CLIENT_CERT_FILE" )
668
- options ["key_file" ] = key_file or os .environ .get ("CLIENT_KEY_FILE" )
650
+ options ["cert_file" ] = self .options ["cert_file" ] or os .environ .get (
651
+ "CLIENT_CERT_FILE"
652
+ )
653
+ options ["key_file" ] = self .options ["key_file" ] or os .environ .get (
654
+ "CLIENT_KEY_FILE"
655
+ )
669
656
670
657
return options
671
658
672
- def _make_pool (
673
- self ,
674
- parsed_dsn , # type: Dsn
675
- http_proxy , # type: Optional[str]
676
- https_proxy , # type: Optional[str]
677
- ca_certs , # type: Any
678
- cert_file , # type: Any
679
- key_file , # type: Any
680
- proxy_headers , # type: Optional[Dict[str, str]]
681
- ):
682
- # type: (...) -> Union[PoolManager, ProxyManager]
659
+ def _make_pool (self ):
660
+ # type: (Self) -> Union[PoolManager, ProxyManager]
661
+ if self .parsed_dsn is None :
662
+ raise ValueError ("Cannot create HTTP-based transport without valid DSN" )
663
+
683
664
proxy = None
684
- no_proxy = self ._in_no_proxy (parsed_dsn )
665
+ no_proxy = self ._in_no_proxy (self . parsed_dsn )
685
666
686
667
# try HTTPS first
687
- if parsed_dsn .scheme == "https" and (https_proxy != "" ):
668
+ https_proxy = self .options ["https_proxy" ]
669
+ if self .parsed_dsn .scheme == "https" and (https_proxy != "" ):
688
670
proxy = https_proxy or (not no_proxy and getproxies ().get ("https" ))
689
671
690
672
# maybe fallback to HTTP proxy
673
+ http_proxy = self .options ["http_proxy" ]
691
674
if not proxy and (http_proxy != "" ):
692
675
proxy = http_proxy or (not no_proxy and getproxies ().get ("http" ))
693
676
694
- opts = self ._get_pool_options (ca_certs , cert_file , key_file )
677
+ opts = self ._get_pool_options ()
695
678
696
679
if proxy :
680
+ proxy_headers = self .options ["proxy_headers" ]
697
681
if proxy_headers :
698
682
opts ["proxy_headers" ] = proxy_headers
699
683
@@ -783,10 +767,11 @@ def _request(
783
767
)
784
768
return response
785
769
786
- def _get_pool_options (self , ca_certs , cert_file = None , key_file = None ):
787
- # type: (Any, Any, Any ) -> Dict[str, Any]
770
+ def _get_pool_options (self ):
771
+ # type: (Self ) -> Dict[str, Any]
788
772
options = {
789
- "http2" : True ,
773
+ "http2" : self .parsed_dsn is not None
774
+ and self .parsed_dsn .scheme == "https" ,
790
775
"retries" : 3 ,
791
776
} # type: Dict[str, Any]
792
777
@@ -805,45 +790,41 @@ def _get_pool_options(self, ca_certs, cert_file=None, key_file=None):
805
790
806
791
ssl_context = ssl .create_default_context ()
807
792
ssl_context .load_verify_locations (
808
- ca_certs # User-provided bundle from the SDK init
793
+ self . options [ " ca_certs" ] # User-provided bundle from the SDK init
809
794
or os .environ .get ("SSL_CERT_FILE" )
810
795
or os .environ .get ("REQUESTS_CA_BUNDLE" )
811
796
or certifi .where ()
812
797
)
813
- cert_file = cert_file or os .environ .get ("CLIENT_CERT_FILE" )
814
- key_file = key_file or os .environ .get ("CLIENT_KEY_FILE" )
798
+ cert_file = self . options [ " cert_file" ] or os .environ .get ("CLIENT_CERT_FILE" )
799
+ key_file = self . options [ " key_file" ] or os .environ .get ("CLIENT_KEY_FILE" )
815
800
if cert_file is not None :
816
801
ssl_context .load_cert_chain (cert_file , key_file )
817
802
818
803
options ["ssl_context" ] = ssl_context
819
804
820
805
return options
821
806
822
- def _make_pool (
823
- self ,
824
- parsed_dsn , # type: Dsn
825
- http_proxy , # type: Optional[str]
826
- https_proxy , # type: Optional[str]
827
- ca_certs , # type: Any
828
- cert_file , # type: Any
829
- key_file , # type: Any
830
- proxy_headers , # type: Optional[Dict[str, str]]
831
- ):
832
- # type: (...) -> Union[httpcore.SOCKSProxy, httpcore.HTTPProxy, httpcore.ConnectionPool]
807
+ def _make_pool (self ):
808
+ # type: (Self) -> Union[httpcore.SOCKSProxy, httpcore.HTTPProxy, httpcore.ConnectionPool]
809
+ if self .parsed_dsn is None :
810
+ raise ValueError ("Cannot create HTTP-based transport without valid DSN" )
833
811
proxy = None
834
- no_proxy = self ._in_no_proxy (parsed_dsn )
812
+ no_proxy = self ._in_no_proxy (self . parsed_dsn )
835
813
836
814
# try HTTPS first
837
- if parsed_dsn .scheme == "https" and (https_proxy != "" ):
815
+ https_proxy = self .options ["https_proxy" ]
816
+ if self .parsed_dsn .scheme == "https" and (https_proxy != "" ):
838
817
proxy = https_proxy or (not no_proxy and getproxies ().get ("https" ))
839
818
840
819
# maybe fallback to HTTP proxy
820
+ http_proxy = self .options ["http_proxy" ]
841
821
if not proxy and (http_proxy != "" ):
842
822
proxy = http_proxy or (not no_proxy and getproxies ().get ("http" ))
843
823
844
- opts = self ._get_pool_options (ca_certs , cert_file , key_file )
824
+ opts = self ._get_pool_options ()
845
825
846
826
if proxy :
827
+ proxy_headers = self .options ["proxy_headers" ]
847
828
if proxy_headers :
848
829
opts ["proxy_headers" ] = proxy_headers
849
830
0 commit comments