diff --git a/src/rights_filter/server/http_app.py b/src/rights_filter/server/http_app.py index d739f3d..c7616d3 100644 --- a/src/rights_filter/server/http_app.py +++ b/src/rights_filter/server/http_app.py @@ -12,6 +12,16 @@ from urllib.parse import unquote, urlparse from rights_filter.server.image_store import LocalSubmissionImageStore, SUPPORTED_IMAGE_SUFFIXES from rights_filter.server.sqlite_store import CopyrighterStore +# Windows Python builds may not know .woff2, which would serve the bundled +# 2MB font as application/octet-stream. +mimetypes.add_type("font/woff2", ".woff2") +mimetypes.add_type("font/woff", ".woff") + +# Bundled font binaries never change between releases; without any cache +# validator the browser re-downloads the full file on every page load. +_IMMUTABLE_SUFFIXES = {".woff2", ".woff"} +_IMMUTABLE_CACHE_CONTROL = "public, max-age=31536000, immutable" + def build_server( host: str, @@ -214,6 +224,8 @@ def build_server( self.send_response(HTTPStatus.OK) self.send_header("Content-Type", content_type) self.send_header("Content-Length", str(len(data))) + if path.suffix.lower() in _IMMUTABLE_SUFFIXES: + self.send_header("Cache-Control", _IMMUTABLE_CACHE_CONTROL) if untrusted: # Neutralize stored XSS from operator-uploaded / externally # collected media (an SVG can carry an inline - -