@@ -204,15 +204,7 @@ def __init__(self, options):
204204 ) # type: DefaultDict[Tuple[EventDataCategory, str], int]
205205 self ._last_client_report_sent = time .time ()
206206
207- self ._pool = self ._make_pool (
208- self .parsed_dsn ,
209- http_proxy = options ["http_proxy" ],
210- https_proxy = options ["https_proxy" ],
211- ca_certs = options ["ca_certs" ],
212- cert_file = options ["cert_file" ],
213- key_file = options ["key_file" ],
214- proxy_headers = options ["proxy_headers" ],
215- )
207+ self ._pool = self ._make_pool ()
216208
217209 experiments = options .get ("_experiments" , {})
218210 compression_level = experiments .get (
@@ -512,8 +504,8 @@ def _serialize_envelope(self, envelope):
512504
513505 return content_encoding , body
514506
515- def _get_pool_options (self , ca_certs , cert_file = None , key_file = None ):
516- # type: (Self, Optional[Any], Optional[Any], Optional[Any] ) -> Dict[str, Any]
507+ def _get_pool_options (self ):
508+ # type: (Self) -> Dict[str, Any]
517509 raise NotImplementedError ()
518510
519511 def _in_no_proxy (self , parsed_dsn ):
@@ -527,17 +519,8 @@ def _in_no_proxy(self, parsed_dsn):
527519 return True
528520 return False
529521
530- def _make_pool (
531- self ,
532- parsed_dsn , # type: Dsn
533- http_proxy , # type: Optional[str]
534- https_proxy , # type: Optional[str]
535- ca_certs , # type: Optional[Any]
536- cert_file , # type: Optional[Any]
537- key_file , # type: Optional[Any]
538- proxy_headers , # type: Optional[Dict[str, str]]
539- ):
540- # type: (...) -> Union[PoolManager, ProxyManager, httpcore.SOCKSProxy, httpcore.HTTPProxy, httpcore.ConnectionPool]
522+ def _make_pool (self ):
523+ # type: (Self) -> Union[PoolManager, ProxyManager, httpcore.SOCKSProxy, httpcore.HTTPProxy, httpcore.ConnectionPool]
541524 raise NotImplementedError ()
542525
543526 def _request (
@@ -587,8 +570,8 @@ class HttpTransport(BaseHttpTransport):
587570 if TYPE_CHECKING :
588571 _pool : Union [PoolManager , ProxyManager ]
589572
590- def _get_pool_options (self , ca_certs , cert_file = None , key_file = None ):
591- # type: (Self, Any, Any, Any ) -> Dict[str, Any]
573+ def _get_pool_options (self ):
574+ # type: (Self) -> Dict[str, Any]
592575
593576 num_pools = self .options .get ("_experiments" , {}).get ("transport_num_pools" )
594577 options = {
@@ -614,42 +597,43 @@ def _get_pool_options(self, ca_certs, cert_file=None, key_file=None):
614597 options ["socket_options" ] = socket_options
615598
616599 options ["ca_certs" ] = (
617- ca_certs # User-provided bundle from the SDK init
600+ self . options [ " ca_certs" ] # User-provided bundle from the SDK init
618601 or os .environ .get ("SSL_CERT_FILE" )
619602 or os .environ .get ("REQUESTS_CA_BUNDLE" )
620603 or certifi .where ()
621604 )
622605
623- options ["cert_file" ] = cert_file or os .environ .get ("CLIENT_CERT_FILE" )
624- options ["key_file" ] = key_file or os .environ .get ("CLIENT_KEY_FILE" )
606+ options ["cert_file" ] = self .options ["cert_file" ] or os .environ .get (
607+ "CLIENT_CERT_FILE"
608+ )
609+ options ["key_file" ] = self .options ["key_file" ] or os .environ .get (
610+ "CLIENT_KEY_FILE"
611+ )
625612
626613 return options
627614
628- def _make_pool (
629- self ,
630- parsed_dsn , # type: Dsn
631- http_proxy , # type: Optional[str]
632- https_proxy , # type: Optional[str]
633- ca_certs , # type: Any
634- cert_file , # type: Any
635- key_file , # type: Any
636- proxy_headers , # type: Optional[Dict[str, str]]
637- ):
638- # type: (...) -> Union[PoolManager, ProxyManager]
615+ def _make_pool (self ):
616+ # type: (Self) -> Union[PoolManager, ProxyManager]
617+ if self .parsed_dsn is None :
618+ raise ValueError ("Cannot create HTTP-based transport without valid DSN" )
619+
639620 proxy = None
640- no_proxy = self ._in_no_proxy (parsed_dsn )
621+ no_proxy = self ._in_no_proxy (self . parsed_dsn )
641622
642623 # try HTTPS first
643- if parsed_dsn .scheme == "https" and (https_proxy != "" ):
624+ https_proxy = self .options ["https_proxy" ]
625+ if self .parsed_dsn .scheme == "https" and (https_proxy != "" ):
644626 proxy = https_proxy or (not no_proxy and getproxies ().get ("https" ))
645627
646628 # maybe fallback to HTTP proxy
629+ http_proxy = self .options ["http_proxy" ]
647630 if not proxy and (http_proxy != "" ):
648631 proxy = http_proxy or (not no_proxy and getproxies ().get ("http" ))
649632
650- opts = self ._get_pool_options (ca_certs , cert_file , key_file )
633+ opts = self ._get_pool_options ()
651634
652635 if proxy :
636+ proxy_headers = self .options ["proxy_headers" ]
653637 if proxy_headers :
654638 opts ["proxy_headers" ] = proxy_headers
655639
@@ -739,10 +723,11 @@ def _request(
739723 )
740724 return response
741725
742- def _get_pool_options (self , ca_certs , cert_file = None , key_file = None ):
743- # type: (Any, Any, Any ) -> Dict[str, Any]
726+ def _get_pool_options (self ):
727+ # type: (Self ) -> Dict[str, Any]
744728 options = {
745- "http2" : True ,
729+ "http2" : self .parsed_dsn is not None
730+ and self .parsed_dsn .scheme == "https" ,
746731 "retries" : 3 ,
747732 } # type: Dict[str, Any]
748733
@@ -761,45 +746,41 @@ def _get_pool_options(self, ca_certs, cert_file=None, key_file=None):
761746
762747 ssl_context = ssl .create_default_context ()
763748 ssl_context .load_verify_locations (
764- ca_certs # User-provided bundle from the SDK init
749+ self . options [ " ca_certs" ] # User-provided bundle from the SDK init
765750 or os .environ .get ("SSL_CERT_FILE" )
766751 or os .environ .get ("REQUESTS_CA_BUNDLE" )
767752 or certifi .where ()
768753 )
769- cert_file = cert_file or os .environ .get ("CLIENT_CERT_FILE" )
770- key_file = key_file or os .environ .get ("CLIENT_KEY_FILE" )
754+ cert_file = self . options [ " cert_file" ] or os .environ .get ("CLIENT_CERT_FILE" )
755+ key_file = self . options [ " key_file" ] or os .environ .get ("CLIENT_KEY_FILE" )
771756 if cert_file is not None :
772757 ssl_context .load_cert_chain (cert_file , key_file )
773758
774759 options ["ssl_context" ] = ssl_context
775760
776761 return options
777762
778- def _make_pool (
779- self ,
780- parsed_dsn , # type: Dsn
781- http_proxy , # type: Optional[str]
782- https_proxy , # type: Optional[str]
783- ca_certs , # type: Any
784- cert_file , # type: Any
785- key_file , # type: Any
786- proxy_headers , # type: Optional[Dict[str, str]]
787- ):
788- # type: (...) -> Union[httpcore.SOCKSProxy, httpcore.HTTPProxy, httpcore.ConnectionPool]
763+ def _make_pool (self ):
764+ # type: (Self) -> Union[httpcore.SOCKSProxy, httpcore.HTTPProxy, httpcore.ConnectionPool]
765+ if self .parsed_dsn is None :
766+ raise ValueError ("Cannot create HTTP-based transport without valid DSN" )
789767 proxy = None
790- no_proxy = self ._in_no_proxy (parsed_dsn )
768+ no_proxy = self ._in_no_proxy (self . parsed_dsn )
791769
792770 # try HTTPS first
793- if parsed_dsn .scheme == "https" and (https_proxy != "" ):
771+ https_proxy = self .options ["https_proxy" ]
772+ if self .parsed_dsn .scheme == "https" and (https_proxy != "" ):
794773 proxy = https_proxy or (not no_proxy and getproxies ().get ("https" ))
795774
796775 # maybe fallback to HTTP proxy
776+ http_proxy = self .options ["http_proxy" ]
797777 if not proxy and (http_proxy != "" ):
798778 proxy = http_proxy or (not no_proxy and getproxies ().get ("http" ))
799779
800- opts = self ._get_pool_options (ca_certs , cert_file , key_file )
780+ opts = self ._get_pool_options ()
801781
802782 if proxy :
783+ proxy_headers = self .options ["proxy_headers" ]
803784 if proxy_headers :
804785 opts ["proxy_headers" ] = proxy_headers
805786
0 commit comments