diff options
author | Kevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com> | 2018-10-09 17:31:06 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-10-09 20:31:06 -0400 |
commit | 888824c61787edb4a1a0d4141f6c08855d87d2b7 (patch) | |
tree | e571448effd72496d1480bc8ec8e04f010f8e0d2 /tools/http_server.py | |
parent | 94889aef08909171ac5dc7b7c9c72c38d439bd7d (diff) |
Add redirect follow feature (#934)
Diffstat (limited to 'tools/http_server.py')
-rwxr-xr-x | tools/http_server.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tools/http_server.py b/tools/http_server.py index fdb8686cd..d33f24d5d 100755 --- a/tools/http_server.py +++ b/tools/http_server.py @@ -9,6 +9,7 @@ from util import root_path from time import sleep PORT = 4545 +REDIRECT_PORT = 4546 def server(): @@ -20,11 +21,35 @@ def server(): return s +def redirect_server(): + os.chdir(root_path) + target_host = "http://localhost:%d" % PORT + + class RedirectHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): + def do_GET(self): + self.send_response(301) + self.send_header('Location', target_host + self.path) + self.end_headers() + + Handler = RedirectHandler + SocketServer.TCPServer.allow_reuse_address = True + s = SocketServer.TCPServer(("", REDIRECT_PORT), Handler) + print "Deno redirect server http://localhost:%d/ -> http://localhost:%d/" % ( + REDIRECT_PORT, PORT) + return s + + def spawn(): + # Main http server s = server() thread = Thread(target=s.serve_forever) thread.daemon = True thread.start() + # Redirect server + rs = redirect_server() + r_thread = Thread(target=rs.serve_forever) + r_thread.daemon = True + r_thread.start() sleep(1) # TODO I'm too lazy to figure out how to do this properly. return thread |