1
1
import http .server
2
2
import json
3
3
import logging
4
+ import random
4
5
import socket
5
6
import sys
6
7
import time
@@ -28,7 +29,8 @@ def find_available_port() -> Optional[int]:
28
29
Optional[int]: An available port number, or None if no ports are available.
29
30
"""
30
31
# Dynamic ports IANA
31
- port_range = range (49152 , 65536 )
32
+ port_range = list (range (49152 , 65536 ))
33
+ random .shuffle (port_range )
32
34
33
35
for port in port_range :
34
36
with socket .socket (socket .AF_INET , socket .SOCK_STREAM ) as s :
@@ -136,6 +138,8 @@ def do_GET(self) -> None:
136
138
if isinstance (c_type , list ) and len (c_type ) == 1 and isinstance (c_type [0 ], str ):
137
139
callback_type = c_type [0 ]
138
140
except Exception :
141
+ msg = "Unable to process the callback, try again."
142
+ self .send_error (400 , msg )
139
143
click .secho ("Unable to process the callback, try again." )
140
144
return
141
145
@@ -158,8 +162,10 @@ def do_redirect(self, location: str, params: Dict) -> None:
158
162
location (str): The URL to redirect to.
159
163
params (dict): Additional parameters for the redirection.
160
164
"""
161
- self .send_response (301 )
165
+ self .send_response (302 )
162
166
self .send_header ('Location' , location )
167
+ self .send_header ('Connection' , 'close' )
168
+ self .send_header ('Cache-Control' , 'no-store, no-cache, must-revalidate' )
163
169
self .end_headers ()
164
170
165
171
def log_message (self , format : str , * args : Any ) -> None :
0 commit comments