Skip to content

Commit

Permalink
fix: skip cache header for 4xx,5xx response
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Dec 28, 2021
1 parent 1e5e17f commit 5beb991
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pol/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from sqlalchemy.orm import sessionmaker
from fastapi.responses import HTMLResponse
from starlette.requests import Request
from starlette.responses import Response
from starlette.exceptions import HTTPException as StarletteHTTPException
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine

Expand All @@ -32,7 +33,9 @@

@app.middleware("http")
async def handle_public_cache(request: Request, call_next):
response = await call_next(request)
response: Response = await call_next(request)
if response.status_code >= 400:
return response
if "authorization" in request.headers:
response.headers["cache-control"] = "no-store"
elif v := getattr(request.state, "public_resource", 0):
Expand Down

0 comments on commit 5beb991

Please sign in to comment.