Merge pull request #149 from naturallaw777/copilot/add-cache-busting-headers
[WIP] Add cache-busting and data-clearing HTTP headers
This commit is contained in:
@@ -23,6 +23,7 @@ from fastapi.staticfiles import StaticFiles
|
|||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
from fastapi.requests import Request
|
from fastapi.requests import Request
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
from starlette.middleware.base import BaseHTTPMiddleware
|
||||||
|
|
||||||
from .config import load_config
|
from .config import load_config
|
||||||
from . import systemctl as sysctl
|
from . import systemctl as sysctl
|
||||||
@@ -428,6 +429,19 @@ _BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|||||||
|
|
||||||
app = FastAPI(title="Sovran_SystemsOS Hub")
|
app = FastAPI(title="Sovran_SystemsOS Hub")
|
||||||
|
|
||||||
|
|
||||||
|
class NoCacheMiddleware(BaseHTTPMiddleware):
|
||||||
|
async def dispatch(self, request, call_next):
|
||||||
|
response = await call_next(request)
|
||||||
|
response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0"
|
||||||
|
response.headers["Pragma"] = "no-cache"
|
||||||
|
response.headers["Expires"] = "0"
|
||||||
|
response.headers["Clear-Site-Data"] = '"cache", "cookies", "storage"'
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
app.add_middleware(NoCacheMiddleware)
|
||||||
|
|
||||||
_ICONS_DIR = os.environ.get(
|
_ICONS_DIR = os.environ.get(
|
||||||
"SOVRAN_HUB_ICONS",
|
"SOVRAN_HUB_ICONS",
|
||||||
os.path.join(os.path.dirname(_BASE_DIR), "icons"),
|
os.path.join(os.path.dirname(_BASE_DIR), "icons"),
|
||||||
|
|||||||
@@ -162,6 +162,12 @@ EOF
|
|||||||
|
|
||||||
http://sovransystemsos.local {
|
http://sovransystemsos.local {
|
||||||
reverse_proxy localhost:8937
|
reverse_proxy localhost:8937
|
||||||
|
header {
|
||||||
|
Clear-Site-Data "\"cache\", \"cookies\", \"storage\""
|
||||||
|
Cache-Control "no-store, no-cache, must-revalidate, max-age=0"
|
||||||
|
Pragma "no-cache"
|
||||||
|
Expires "0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user