This commit is contained in:
@@ -83,6 +83,50 @@ class ProxyStaticHandler(SimpleHTTPRequestHandler):
|
||||
return self._proxy_request()
|
||||
return super().do_GET()
|
||||
|
||||
def send_head(self):
|
||||
import os
|
||||
from urllib.parse import unquote
|
||||
from http import HTTPStatus
|
||||
path = self.translate_path(self.path)
|
||||
f = None
|
||||
if os.path.isdir(path):
|
||||
parts = self.path.split("?", 1)
|
||||
if not parts[0].endswith("/"):
|
||||
self.send_response(HTTPStatus.MOVED_PERMANENTLY)
|
||||
self.send_header("Location", parts[0] + "/")
|
||||
self.end_headers()
|
||||
return None
|
||||
for index in "index.html", "index.htm":
|
||||
index = os.path.join(path, index)
|
||||
if os.path.exists(index):
|
||||
path = index
|
||||
break
|
||||
else:
|
||||
return self.list_directory(path)
|
||||
ctype = self.guess_type(path)
|
||||
try:
|
||||
f = open(path, "rb")
|
||||
except OSError:
|
||||
self.send_error(HTTPStatus.NOT_FOUND, "File not found")
|
||||
return None
|
||||
try:
|
||||
fs = os.fstat(f.fileno())
|
||||
content_length = str(int(fs[6]))
|
||||
self.send_response(HTTPStatus.OK)
|
||||
self.send_header("Content-Type", ctype)
|
||||
self.send_header("Content-Length", content_length)
|
||||
if "text/html" in ctype or "text/javascript" in ctype or "application/javascript" in ctype:
|
||||
self.send_header("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
self.send_header("Pragma", "no-cache")
|
||||
self.send_header("Expires", "0")
|
||||
self.send_header("Last-Modified", self.date_time_string(fs.st_mtime))
|
||||
self.end_headers()
|
||||
return f
|
||||
except:
|
||||
f.close()
|
||||
raise
|
||||
return result
|
||||
|
||||
def do_POST(self):
|
||||
if self.path.startswith("/api"):
|
||||
return self._proxy_request()
|
||||
|
||||
Reference in New Issue
Block a user