Fix work recovery and reduce engine and chart overhead
Docs / docs (push) Successful in 33s
Playwright Tests / test-playwright (1, 2) (push) Failing after 1m37s
Playwright Tests / test-playwright (2, 2) (push) Failing after 27s
pre-commit / pre-commit (push) Failing after 2m37s
Test Backend / test-backend (3.12) (push) Successful in 5m7s
Test Backend / test-backend (3.14) (push) Successful in 5m2s
Compose Smoke Test / test-compose (push) Failing after 28s
Playwright Tests / merge-reports (push) Failing after 2m29s
Docs / docs (push) Successful in 33s
Playwright Tests / test-playwright (1, 2) (push) Failing after 1m37s
Playwright Tests / test-playwright (2, 2) (push) Failing after 27s
pre-commit / pre-commit (push) Failing after 2m37s
Test Backend / test-backend (3.12) (push) Successful in 5m7s
Test Backend / test-backend (3.14) (push) Successful in 5m2s
Compose Smoke Test / test-compose (push) Failing after 28s
Playwright Tests / merge-reports (push) Failing after 2m29s
This commit is contained in:
+28
-3
@@ -15,7 +15,7 @@ import mimetypes
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
from starlette.middleware.gzip import GZipMiddleware
|
||||
from starlette.datastructures import Headers
|
||||
from starlette.responses import FileResponse
|
||||
from starlette.types import ASGIApp, Receive, Scope, Send
|
||||
|
||||
@@ -26,6 +26,24 @@ API_PREFIXES = ("/api/", "/hooks/", "/mcp", "/.well-known/", "/docs", "/redoc")
|
||||
mimetypes.add_type("application/manifest+json", ".webmanifest")
|
||||
|
||||
|
||||
def _accepts_gzip(header: str) -> bool:
|
||||
"""An explicit refusal overrides a wildcard, including on a cached asset."""
|
||||
qualities: dict[str, float] = {}
|
||||
for entry in header.lower().split(","):
|
||||
encoding, *parameters = entry.strip().split(";")
|
||||
quality = 1.0
|
||||
for parameter in parameters:
|
||||
key, _, value = parameter.strip().partition("=")
|
||||
if key == "q":
|
||||
try:
|
||||
quality = float(value)
|
||||
except ValueError:
|
||||
quality = 0.0
|
||||
qualities[encoding.strip()] = quality if 0.0 <= quality <= 1.0 else 0.0
|
||||
gzip = qualities.get("gzip", qualities.get("*", 0.0))
|
||||
return gzip > 0 and gzip >= qualities.get("identity", 0.0)
|
||||
|
||||
|
||||
def content_security_policy(index_html: str) -> str:
|
||||
"""The policy for the dashboard, admitting its inline scripts by hash.
|
||||
|
||||
@@ -84,5 +102,12 @@ class Dashboard:
|
||||
# assets, so a stale copy pins the browser to the previous build.
|
||||
file = self.index
|
||||
headers = {**self.headers, "Cache-Control": "no-cache"}
|
||||
response = FileResponse(file, headers=headers)
|
||||
await GZipMiddleware(response, minimum_size=1024)(scope, receive, send)
|
||||
media_type = mimetypes.guess_type(file.name)[0] or "text/plain"
|
||||
compressed = file.with_name(file.name + ".gz").resolve()
|
||||
if compressed.is_relative_to(self.dist) and compressed.is_file():
|
||||
headers["Vary"] = "Accept-Encoding"
|
||||
if _accepts_gzip(Headers(scope=scope).get("accept-encoding", "")):
|
||||
file = compressed
|
||||
headers["Content-Encoding"] = "gzip"
|
||||
response = FileResponse(file, headers=headers, media_type=media_type)
|
||||
await response(scope, receive, send)
|
||||
|
||||
Reference in New Issue
Block a user