@@ -98,6 +98,7 @@ def __init__(self,
9898 self .host = host
9999 self .port = port
100100 self .proxy_host = proxy_host
101+ self .proxy_port = None
101102 self .secure = secure
102103 self .daemon = True
103104
@@ -111,8 +112,8 @@ def _start_proxy(self):
111112 for sock in [tx_sock , rx_sock ]:
112113 sock .setsockopt (socket .SOL_SOCKET , socket .SO_REUSEADDR , 1 )
113114
114- sock_rx .bind ((self .proxy_host , 0 ))
115- self .proxy_port = sock_rx .getsockname ()[1 ]
115+ rx_sock .bind ((self .proxy_host , 0 ))
116+ self .proxy_port = rx_sock .getsockname ()[1 ]
116117
117118 # Once listen() returns, the server socket is ready
118119 rx_sock .listen (1 )
@@ -164,6 +165,7 @@ def _start_server(self, socket_handler):
164165
165166 self .proxy_host = self .proxy_thread .proxy_host
166167 self .proxy_port = self .proxy_thread .proxy_port
168+ self .secure = self .proxy_thread .secure
167169
168170 def _start_proxy (self ):
169171 """
@@ -172,25 +174,20 @@ def _start_proxy(self):
172174 def _proxy_socket_handler (tx_sock , rx_sock ):
173175 rx_sock_add = rx_sock .accept ()[0 ]
174176 tx_sock .send (rx_sock_add .recv (65535 ))
175- rx_sock_add = sock .close ()
177+ rx_sock_add .close ()
176178
177179 self .proxy_thread = SocketProxyThread (
178- socket_handler = _proxy_socket_handler
180+ socket_handler = _proxy_socket_handler ,
181+ host = self .host ,
182+ port = self .port
179183 )
180184 self .proxy_thread .start ()
181185
182186 def get_connection (self ):
183- if not self .proxy :
184- host = self .host
185- port = self .port
186- else :
187- host = self .proxy_host
188- port = self .proxy_port
189-
190187 if self .h2 :
191- return HTTP20Connection (host , port , self .secure )
188+ return HTTP20Connection (self . host , self . port , self .secure , proxy = ':' . join ([ self . proxy_host , self . proxy_port ]) if self . proxy else None )
192189 else :
193- return HTTP11Connection (host , port , self .secure )
190+ return HTTP11Connection (self . host , self . port , self .secure , proxy = ':' . join ([ self . proxy_host , self . proxy_port ]) if self . proxy else None )
194191
195192 def get_encoder (self ):
196193 """
0 commit comments