@@ -98,6 +98,7 @@ def __init__(self,
98
98
self .host = host
99
99
self .port = port
100
100
self .proxy_host = proxy_host
101
+ self .proxy_port = None
101
102
self .secure = secure
102
103
self .daemon = True
103
104
@@ -111,8 +112,8 @@ def _start_proxy(self):
111
112
for sock in [tx_sock , rx_sock ]:
112
113
sock .setsockopt (socket .SOL_SOCKET , socket .SO_REUSEADDR , 1 )
113
114
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 ]
116
117
117
118
# Once listen() returns, the server socket is ready
118
119
rx_sock .listen (1 )
@@ -164,6 +165,7 @@ def _start_server(self, socket_handler):
164
165
165
166
self .proxy_host = self .proxy_thread .proxy_host
166
167
self .proxy_port = self .proxy_thread .proxy_port
168
+ self .secure = self .proxy_thread .secure
167
169
168
170
def _start_proxy (self ):
169
171
"""
@@ -172,25 +174,20 @@ def _start_proxy(self):
172
174
def _proxy_socket_handler (tx_sock , rx_sock ):
173
175
rx_sock_add = rx_sock .accept ()[0 ]
174
176
tx_sock .send (rx_sock_add .recv (65535 ))
175
- rx_sock_add = sock .close ()
177
+ rx_sock_add .close ()
176
178
177
179
self .proxy_thread = SocketProxyThread (
178
- socket_handler = _proxy_socket_handler
180
+ socket_handler = _proxy_socket_handler ,
181
+ host = self .host ,
182
+ port = self .port
179
183
)
180
184
self .proxy_thread .start ()
181
185
182
186
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
-
190
187
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 )
192
189
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 )
194
191
195
192
def get_encoder (self ):
196
193
"""
0 commit comments