Disable GUI asset caching
This commit is contained in:
parent
3802434f19
commit
30e230fae9
2 changed files with 58 additions and 0 deletions
|
|
@ -374,6 +374,15 @@ def create_app():
|
|||
jobs: dict[str, GuiJob] = {}
|
||||
static_dir = _static_dir()
|
||||
|
||||
@app.middleware("http")
|
||||
async def disable_gui_asset_caching(request, call_next):
|
||||
response = await call_next(request)
|
||||
if request.url.path == "/" or request.url.path.startswith("/app"):
|
||||
response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0"
|
||||
response.headers["Pragma"] = "no-cache"
|
||||
response.headers["Expires"] = "0"
|
||||
return response
|
||||
|
||||
@app.get("/api/health")
|
||||
def health() -> dict[str, str]:
|
||||
return {"status": "ok"}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from __future__ import annotations
|
|||
|
||||
import importlib.util
|
||||
import io
|
||||
import asyncio
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
|
|
@ -16,6 +17,39 @@ from repixelizer.params import SolverHyperParams
|
|||
from repixelizer.types import InferenceCandidate, InferenceResult, PhaseFieldSourceAnalysis, SolverArtifacts
|
||||
|
||||
|
||||
async def _get_response_headers(app, path: str) -> tuple[int, dict[str, str]]:
|
||||
messages: list[dict[str, object]] = []
|
||||
|
||||
async def receive():
|
||||
return {"type": "http.request", "body": b"", "more_body": False}
|
||||
|
||||
async def send(message):
|
||||
messages.append(message)
|
||||
|
||||
scope = {
|
||||
"type": "http",
|
||||
"asgi": {"version": "3.0"},
|
||||
"http_version": "1.1",
|
||||
"method": "GET",
|
||||
"scheme": "http",
|
||||
"path": path,
|
||||
"raw_path": path.encode("ascii"),
|
||||
"query_string": b"",
|
||||
"headers": [],
|
||||
"client": ("127.0.0.1", 12345),
|
||||
"server": ("testserver", 80),
|
||||
"root_path": "",
|
||||
}
|
||||
await app(scope, receive, send)
|
||||
start = next(message for message in messages if message["type"] == "http.response.start")
|
||||
status = int(start["status"])
|
||||
headers = {
|
||||
key.decode("latin-1").lower(): value.decode("latin-1")
|
||||
for key, value in start.get("headers", [])
|
||||
}
|
||||
return status, headers
|
||||
|
||||
|
||||
def test_run_pipeline_rgba_emits_observer_events_for_gui() -> None:
|
||||
source = make_emblem(20, 20)
|
||||
fake = fake_pixelize(source, upscale=8, phase_x=0.15, phase_y=0.2, blur_radius=0.45, seed=3)
|
||||
|
|
@ -88,6 +122,21 @@ def test_create_job_upload_field_validates_without_forward_ref_errors() -> None:
|
|||
assert value.filename == "tiny.png"
|
||||
|
||||
|
||||
def test_gui_static_assets_disable_browser_caching() -> None:
|
||||
from repixelizer.gui import create_app
|
||||
|
||||
app = create_app()
|
||||
html_status, html_headers = asyncio.run(_get_response_headers(app, "/app/"))
|
||||
js_status, js_headers = asyncio.run(_get_response_headers(app, "/app/app.js"))
|
||||
|
||||
assert html_status == 200
|
||||
assert js_status == 200
|
||||
assert html_headers["cache-control"] == "no-store, no-cache, must-revalidate, max-age=0"
|
||||
assert js_headers["cache-control"] == "no-store, no-cache, must-revalidate, max-age=0"
|
||||
assert html_headers["pragma"] == "no-cache"
|
||||
assert js_headers["pragma"] == "no-cache"
|
||||
|
||||
|
||||
def test_infer_lattice_emits_search_progress_events(monkeypatch) -> None:
|
||||
class _FakeCuda:
|
||||
@staticmethod
|
||||
|
|
|
|||
Loading…
Reference in a new issue