🐛 Add workaround for fastapi-cache issue #144
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
import uvicorn
|
||||
from contextlib import asynccontextmanager
|
||||
from fastapi import FastAPI
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi_cache import FastAPICache
|
||||
@@ -43,6 +43,24 @@ app.add_middleware(
|
||||
|
||||
app.mount("/widget", StaticFiles(directory="../frontend/", html=True), name="widget")
|
||||
|
||||
# The cache-control header entry is not managed properly by fastapi-cache:
|
||||
# For now, a request with a cache-control set to no-cache
|
||||
# is interpreted as disabling the use of the server cache.
|
||||
# Cf. Improve Cache-Control header parsing and handling
|
||||
# https://github.com/long2ice/fastapi-cache/issues/144 workaround
|
||||
@app.middleware("http")
|
||||
async def fastapi_cache_issue_144_workaround(request: Request, call_next):
|
||||
entries = request.headers.__dict__["_list"]
|
||||
new_entries = [
|
||||
entry for entry in entries if entry[0].decode().lower() != "cache-control"
|
||||
]
|
||||
|
||||
request.headers.__dict__["_list"] = new_entries
|
||||
|
||||
return await call_next(request)
|
||||
|
||||
|
||||
|
||||
app.include_router(line.router)
|
||||
app.include_router(stop.router)
|
||||
|
||||
|
Reference in New Issue
Block a user