@@ -23,11 +23,13 @@ def __init__(self, response: Response):
2323 self .reason = response .reason_phrase
2424 self .resp = response
2525 self .headers = response .headers
26-
26+
2727 # Log HTTP protocol version
28- http_version = getattr (response , 'http_version' , 'Unknown' )
29- logger .debug (f"HTTP response received - Status: { self .status } , Protocol: { http_version } " )
30-
28+ http_version = getattr (response , "http_version" , "Unknown" )
29+ logger .debug (
30+ f"HTTP response received - Status: { self .status } , Protocol: { http_version } "
31+ )
32+
3133 # Log HTTP/2 usage
3234 if http_version == "HTTP/2" :
3335 logger .info (f"HTTP/2 connection established - URL: { response .url } " )
@@ -53,12 +55,12 @@ def data(self) -> bytes:
5355 def text (self ) -> str :
5456 """Get response data as text."""
5557 return self .resp .text
56-
58+
5759 @property
5860 def http_version (self ) -> str :
5961 """Get the HTTP protocol version used."""
60- return getattr (self .resp , ' http_version' , ' Unknown' )
61-
62+ return getattr (self .resp , " http_version" , " Unknown" )
63+
6264 def is_http2 (self ) -> bool :
6365 """Check if HTTP/2 was used for this response."""
6466 return self .http_version == "HTTP/2"
@@ -67,32 +69,61 @@ def is_http2(self) -> bool:
6769class RESTClientObjectAdapter (RESTClientObject ):
6870 """HTTP client adapter using httpx instead of requests."""
6971
70- def __init__ (self , connection : Optional [httpx .Client ] = None ):
71- """Initialize the REST client with httpx."""
72- # Don't call super().__init__() to avoid requests initialization
73- self .connection = connection or httpx .Client (
74- timeout = httpx .Timeout (120.0 ),
75- follow_redirects = True ,
76- limits = httpx .Limits (max_keepalive_connections = 20 , max_connections = 100 ),
77- )
72+ def __init__ (self , connection : Optional [httpx .Client ] = None , configuration = None ):
73+ """
74+ Initialize the REST client with httpx.
75+
76+ Args:
77+ connection: Pre-configured httpx.Client instance. If provided,
78+ proxy settings from configuration will be ignored.
79+ configuration: Configuration object containing proxy settings.
80+ Expected attributes: proxy (str), proxy_headers (dict)
81+ """
82+ if connection is not None :
83+ self .connection = connection
84+ else :
85+ client_kwargs = {
86+ "timeout" : httpx .Timeout (120.0 ),
87+ "follow_redirects" : True ,
88+ "limits" : httpx .Limits (
89+ max_keepalive_connections = 20 , max_connections = 100
90+ ),
91+ }
92+
93+ if (
94+ configuration
95+ and hasattr (configuration , "proxy" )
96+ and configuration .proxy
97+ ):
98+ client_kwargs ["proxy" ] = configuration .proxy
99+ if (
100+ configuration
101+ and hasattr (configuration , "proxy_headers" )
102+ and configuration .proxy_headers
103+ ):
104+ client_kwargs ["proxy_headers" ] = configuration .proxy_headers
105+
106+ self .connection = httpx .Client (** client_kwargs )
78107
79108 def close (self ):
80109 """Close the HTTP client connection."""
81110 if hasattr (self , "connection" ) and self .connection :
82111 self .connection .close ()
83-
112+
84113 def check_http2_support (self , url : str ) -> bool :
85114 """Check if the server supports HTTP/2 by making a test request."""
86115 try :
87116 logger .info (f"Checking HTTP/2 support for: { url } " )
88117 response = self .GET (url )
89118 is_http2 = response .is_http2 ()
90-
119+
91120 if is_http2 :
92121 logger .info (f"✓ HTTP/2 supported by { url } " )
93122 else :
94- logger .info (f"✗ HTTP/2 not supported by { url } , using { response .http_version } " )
95-
123+ logger .info (
124+ f"✗ HTTP/2 not supported by { url } , using { response .http_version } "
125+ )
126+
96127 return is_http2
97128 except Exception as e :
98129 logger .error (f"Failed to check HTTP/2 support for { url } : { e } " )
@@ -151,7 +182,7 @@ def request(
151182 try :
152183 # Log the request attempt
153184 logger .debug (f"Making HTTP request - Method: { method } , URL: { url } " )
154-
185+
155186 # Prepare request parameters
156187 request_kwargs = {
157188 "method" : method ,
0 commit comments