summaryrefslogtreecommitdiff
path: root/tools/http_server.py
diff options
context:
space:
mode:
authorKevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com>2020-02-28 06:04:18 -0800
committerGitHub <noreply@github.com>2020-02-28 09:04:18 -0500
commitb5bf28e68f38396defd50be4ac72ae19a6bf5eb5 (patch)
tree1cd5832fd23c6139c2a10c931ccd1fc5aec86d91 /tools/http_server.py
parent9b6a9b769ed6df9d24dc0c5173cf2590a4bdcb47 (diff)
fetch_cached_remote_source support redirect URL without base (#4099)
Diffstat (limited to 'tools/http_server.py')
-rwxr-xr-xtools/http_server.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/tools/http_server.py b/tools/http_server.py
index 7cb2e28f9..0ed61465c 100755
--- a/tools/http_server.py
+++ b/tools/http_server.py
@@ -21,6 +21,7 @@ REDIRECT_PORT = 4546
ANOTHER_REDIRECT_PORT = 4547
DOUBLE_REDIRECTS_PORT = 4548
INF_REDIRECTS_PORT = 4549
+REDIRECT_ABSOLUTE_PORT = 4550
HTTPS_PORT = 5545
@@ -284,6 +285,29 @@ def inf_redirects_server():
return base_redirect_server(INF_REDIRECTS_PORT, INF_REDIRECTS_PORT)
+# redirect server that redirect to absolute paths under same host
+# redirects /REDIRECT/file_name to /file_name
+def absolute_redirect_server():
+ os.chdir(root_path)
+
+ class AbsoluteRedirectHandler(ContentTypeHandler):
+ def do_GET(self):
+ print(self.path)
+ if (self.path.startswith("/REDIRECT/")):
+ self.send_response(302)
+ self.send_header('Location',
+ self.path.split('/REDIRECT', 1)[1])
+ self.end_headers()
+ else:
+ ContentTypeHandler.do_GET(self)
+
+ s = get_socket(REDIRECT_ABSOLUTE_PORT, AbsoluteRedirectHandler, False)
+ if not QUIET:
+ print("absolute redirect server http://localhost:%d/" %
+ REDIRECT_ABSOLUTE_PORT)
+ return RunningServer(s, start(s))
+
+
def https_server():
os.chdir(root_path) # Hopefully the main thread doesn't also chdir.
Handler = ContentTypeHandler
@@ -310,7 +334,8 @@ def start(s):
@contextmanager
def spawn():
servers = (server(), redirect_server(), another_redirect_server(),
- double_redirects_server(), https_server())
+ double_redirects_server(), https_server(),
+ absolute_redirect_server())
# In order to wait for each of the servers to be ready, we try connecting to
# them with a tcp socket.
for running_server in servers: