@@ -34,7 +34,8 @@ class ProxyServer:
3434 # pylint: disable=too-many-locals
3535 def __init__ (self , host , port , debug , access_log , block_log ,
3636 html_403 , no_filter , filter_mode , no_logging_access , no_logging_block , ssl_inspect ,
37- blocked_sites , blocked_url , shortcuts , inspect_ca_cert , inspect_ca_key , inspect_certs_folder ):
37+ blocked_sites , blocked_url , shortcuts , inspect_ca_cert ,
38+ inspect_ca_key , inspect_certs_folder ):
3839 """
3940 Initializes the ProxyServer instance with the provided configurations.
4041 """
@@ -204,12 +205,12 @@ def handle_http_request(self, client_socket, request):
204205 print (shortcut_url )
205206 if shortcut_url :
206207 response = (
207- "HTTP/1.1 302 Found\r \n "
208- "Location: {shortcut_url}\r \n "
209- "Content-Length: 0\r \n "
208+ f "HTTP/1.1 302 Found\r \n "
209+ f "Location: { shortcut_url } \r \n "
210+ f "Content-Length: 0\r \n "
210211 "\r \n "
211- ). format ( shortcut_url = shortcut_url )
212-
212+ )
213+
213214 client_socket .sendall (response .encode ())
214215 client_socket .close ()
215216 return
@@ -268,16 +269,16 @@ def forward_request_to_server(self, client_socket, request, url):
268269 client_socket .send (response )
269270 else :
270271 break
271- except Exception as e :
272- self .console_logger .error (f "Error connecting to the server { server_host } : { e } " )
272+ except ( socket . timeout , socket . gaierror , ConnectionRefusedError , OSError ) as e :
273+ self .console_logger .error ("Error connecting to the server %s : %s" , server_host , e )
273274 response = (
274275 f"HTTP/1.1 502 Bad Gateway\r \n "
275276 f"Content-Length: { len ('Bad Gateway' )} \r \n "
276- f "\r \n "
277+ "\r \n "
277278 f"Bad Gateway"
278279 )
279280 client_socket .sendall (response .encode ())
280- client_socket .close ()
281+ client_socket .close ()
281282
282283 def parse_url (self , url ):
283284 """
@@ -443,16 +444,16 @@ def handle_https_connection(self, client_socket, first_line):
443444 first_line
444445 )
445446 self .transfer_data_between_sockets (client_socket , server_socket )
446- except Exception as e :
447- self .console_logger .error (f "Error connecting to the server { server_host } : { e } " )
447+ except ( socket . timeout , socket . gaierror , ConnectionRefusedError , OSError ) as e :
448+ self .console_logger .error ("Error connecting to the server %s: %s" , server_host , e )
448449 response = (
449450 f"HTTP/1.1 502 Bad Gateway\r \n "
450451 f"Content-Length: { len ('Bad Gateway' )} \r \n "
451452 f"\r \n "
452453 f"Bad Gateway"
453454 )
454455 client_socket .sendall (response .encode ())
455- client_socket .close ()
456+ client_socket .close ()
456457
457458 def transfer_data_between_sockets (self , client_socket , server_socket ):
458459 """
0 commit comments