Skip to content

Commit

Permalink
Add Cache-control: no-store header to all responses.
Browse files Browse the repository at this point in the history
(Whitenoise is taking care of static content, so no changes needed there.)
  • Loading branch information
brunns committed Jul 25, 2024
1 parent 9d6f302 commit b653959
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions django_app/redbox_app/redbox_core/middleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from asgiref.sync import iscoroutinefunction
from django.http import HttpRequest, HttpResponse
from django.utils.decorators import sync_and_async_middleware


@sync_and_async_middleware
def nocache_middleware(get_response):
if iscoroutinefunction(get_response):

async def middleware(request: HttpRequest) -> HttpResponse:
response = await get_response(request)
response["Cache-Control"] = "no-store"
return response

else:

def middleware(request: HttpRequest) -> HttpResponse:
response = get_response(request)
response["Cache-Control"] = "no-store"
return response

return middleware
1 change: 1 addition & 0 deletions django_app/redbox_app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"django_permissions_policy.PermissionsPolicyMiddleware",
"csp.middleware.CSPMiddleware",
"allauth.account.middleware.AccountMiddleware",
"redbox_app.redbox_core.middleware.nocache_middleware",
]

ROOT_URLCONF = "redbox_app.urls"
Expand Down

0 comments on commit b653959

Please sign in to comment.