-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Cache-control: no-store header to all responses.
(Whitenoise is taking care of static content, so no changes needed there.)
- Loading branch information
Showing
2 changed files
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters