fix
This commit is contained in:
@@ -112,10 +112,31 @@ let
|
|||||||
or headers.get("X-Original-Host")
|
or headers.get("X-Original-Host")
|
||||||
or headers.get("Host", "")
|
or headers.get("Host", "")
|
||||||
)
|
)
|
||||||
host = (host or "").split(",", 1)[0].split(":", 1)[0].strip().lower()
|
return (host or "").split(",", 1)[0].split(":", 1)[0].strip().lower().rstrip(".")
|
||||||
if APP_DOMAIN and host.endswith(f".{APP_DOMAIN}"):
|
|
||||||
return host[:-(len(APP_DOMAIN) + 1)]
|
def _host_candidates(host):
|
||||||
return host
|
candidates = []
|
||||||
|
|
||||||
|
def add(candidate):
|
||||||
|
if candidate and candidate not in candidates:
|
||||||
|
candidates.append(candidate)
|
||||||
|
|
||||||
|
add(host)
|
||||||
|
if APP_DOMAIN:
|
||||||
|
suffix = f".{APP_DOMAIN}"
|
||||||
|
if host.endswith(suffix):
|
||||||
|
add(host[: -len(suffix)].rstrip("."))
|
||||||
|
if "." in host:
|
||||||
|
add(host.split(".", 1)[0])
|
||||||
|
|
||||||
|
return candidates
|
||||||
|
|
||||||
|
def _profile_for_host(host):
|
||||||
|
for candidate in _host_candidates(host):
|
||||||
|
profile = MAPPINGS.get(candidate)
|
||||||
|
if profile:
|
||||||
|
return candidate, profile
|
||||||
|
return None, DEFAULT_PROFILE
|
||||||
|
|
||||||
def _replace_svg_color(svg, attribute, color):
|
def _replace_svg_color(svg, attribute, color):
|
||||||
if attribute in {"fill", "stroke"}:
|
if attribute in {"fill", "stroke"}:
|
||||||
@@ -194,7 +215,7 @@ let
|
|||||||
|
|
||||||
def _serve(self, include_body):
|
def _serve(self, include_body):
|
||||||
host = _request_host(self.headers)
|
host = _request_host(self.headers)
|
||||||
profile = MAPPINGS.get(host) or DEFAULT_PROFILE
|
matched_host, profile = _profile_for_host(host)
|
||||||
if not profile:
|
if not profile:
|
||||||
self.send_error(404, "No favicon mapping for host")
|
self.send_error(404, "No favicon mapping for host")
|
||||||
return
|
return
|
||||||
@@ -209,6 +230,8 @@ let
|
|||||||
self.send_response(304)
|
self.send_response(304)
|
||||||
self.send_header("ETag", etag)
|
self.send_header("ETag", etag)
|
||||||
self.send_header("Cache-Control", CACHE_CONTROL)
|
self.send_header("Cache-Control", CACHE_CONTROL)
|
||||||
|
self.send_header("X-Favicon-Host", host or "default")
|
||||||
|
self.send_header("X-Favicon-Mapping", matched_host or "default")
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -218,6 +241,8 @@ let
|
|||||||
self.send_header("Content-Length", str(len(payload)))
|
self.send_header("Content-Length", str(len(payload)))
|
||||||
self.send_header("Cache-Control", CACHE_CONTROL)
|
self.send_header("Cache-Control", CACHE_CONTROL)
|
||||||
self.send_header("ETag", etag)
|
self.send_header("ETag", etag)
|
||||||
|
self.send_header("X-Favicon-Host", host or "default")
|
||||||
|
self.send_header("X-Favicon-Mapping", matched_host or "default")
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
if include_body:
|
if include_body:
|
||||||
self.wfile.write(payload)
|
self.wfile.write(payload)
|
||||||
|
|||||||
Reference in New Issue
Block a user