webserver: Send pages gzip compressed.
- Also don't need POST or HEAD.
This commit is contained in:
parent
d5fd64c42c
commit
2d9a475833
1 changed files with 4 additions and 9 deletions
|
|
@ -25,7 +25,7 @@ Example:
|
||||||
|
|
||||||
|
|
||||||
def make_page(body_html, title):
|
def make_page(body_html, title):
|
||||||
return f"""
|
text = f"""
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>{title}</title>
|
<title>{title}</title>
|
||||||
|
|
@ -37,6 +37,7 @@ def make_page(body_html, title):
|
||||||
</head>
|
</head>
|
||||||
<body>{body_html}</body>
|
<body>{body_html}</body>
|
||||||
</html>"""
|
</html>"""
|
||||||
|
return gzip.compress(text.encode("utf-8"))
|
||||||
|
|
||||||
|
|
||||||
def make_main_body():
|
def make_main_body():
|
||||||
|
|
@ -70,6 +71,7 @@ class Webserver(http.server.BaseHTTPRequestHandler):
|
||||||
def _set_headers(self):
|
def _set_headers(self):
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
self.send_header("Content-type", "text/html")
|
self.send_header("Content-type", "text/html")
|
||||||
|
self.send_header("Content-encoding", "gzip")
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
|
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
|
|
@ -82,14 +84,7 @@ class Webserver(http.server.BaseHTTPRequestHandler):
|
||||||
page = make_listing_page(self.path[1:])
|
page = make_listing_page(self.path[1:])
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
self.wfile.write(page.encode("utf-8"))
|
self.wfile.write(page)
|
||||||
|
|
||||||
def do_HEAD(self):
|
|
||||||
self._set_headers()
|
|
||||||
|
|
||||||
def do_POST(self):
|
|
||||||
self._set_headers()
|
|
||||||
self.wfile.write("posted".encode("utf-8"))
|
|
||||||
|
|
||||||
|
|
||||||
def make_main_page(project_name):
|
def make_main_page(project_name):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue