From b225151d9937306e67abd28a59a7864c1edd23f3 Mon Sep 17 00:00:00 2001 From: gilesb Date: Fri, 9 Jan 2026 11:59:26 +0000 Subject: [PATCH] Fix content negotiation - default to HTML, not raw data The /cache/{hash} endpoint now defaults to HTML for browsers. Raw data was being returned for requests without explicit text/html in Accept header (e.g., link clicks). JSON is only returned when explicitly requested. Raw data is served only from /cache/{hash}/raw. Co-Authored-By: Claude Opus 4.5 --- server.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/server.py b/server.py index f186088..4ac2bf2 100644 --- a/server.py +++ b/server.py @@ -1991,8 +1991,8 @@ async def get_cached(content_hash: str, request: Request): return HTMLResponse(render_page("Not Found", content, ctx.actor_id if ctx else None, active_tab="media"), status_code=404) raise HTTPException(404, f"Content {content_hash} not in cache") - # JSON response for API clients - if "application/json" in accept: + # JSON response only if explicitly requested + if "application/json" in accept and "text/html" not in accept: t0 = time.time() meta = await database.load_item_metadata(content_hash, ctx.actor_id if ctx else None) logger.debug(f"get_cached: load_item_metadata took {time.time()-t0:.3f}s") @@ -2018,8 +2018,9 @@ async def get_cached(content_hash: str, request: Request): "meta": meta } - # HTML response for browsers - show detail page - if wants_html(request): + # HTML response for browsers (default for all non-JSON requests) + # Raw data is only served from /cache/{hash}/raw endpoint + if True: # Always show HTML page, raw data via /raw endpoint if not ctx: content = '

Login via L2 to view cached content.

' return HTMLResponse(render_page("Login Required", content, None, active_tab="media"), status_code=401) @@ -2157,9 +2158,6 @@ async def get_cached(content_hash: str, request: Request): return HTMLResponse(render_page(f"Cache: {content_hash[:16]}...", content, ctx.actor_id, active_tab="media")) - # Default: return raw file - return FileResponse(cache_path) - @app.get("/cache/{content_hash}/raw") async def get_cached_raw(content_hash: str):