Fix content negotiation for browser navigation
Check Sec-Fetch-Mode: navigate header for direct browser access.
This ensures /cache/{hash} shows HTML detail page when navigating
directly, but still serves raw files for embedded <img>/<video> tags.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3375,7 +3375,14 @@ async def get_user_from_cookie(request) -> Optional[str]:
|
||||
def wants_html(request: Request) -> bool:
|
||||
"""Check if request wants HTML (browser) vs JSON (API)."""
|
||||
accept = request.headers.get("accept", "")
|
||||
return "text/html" in accept and "application/json" not in accept
|
||||
# Check for explicit HTML request
|
||||
if "text/html" in accept and "application/json" not in accept:
|
||||
return True
|
||||
# Check for browser navigation (direct URL access)
|
||||
fetch_mode = request.headers.get("sec-fetch-mode", "")
|
||||
if fetch_mode == "navigate":
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
# Tailwind CSS config for all L1 templates
|
||||
|
||||
Reference in New Issue
Block a user