Set Cache-Control: no-cache on every response

This commit is contained in:
Neil Martinsen-Burrell 2023-11-15 14:29:43 -06:00
parent 093c34a787
commit 0dd158bdd8
No known key found for this signature in database
GPG key ID: 6A3C818CC10D0184
2 changed files with 19 additions and 0 deletions

View file

@ -136,6 +136,8 @@ MIDDLEWARE = [
"allow_cidr.middleware.AllowCIDRMiddleware",
# django-cors-headers: listen to cors responses
"corsheaders.middleware.CorsMiddleware",
# custom middleware to stop caching from CloudFront
"registrar.no_cache_middleware.NoCacheMiddleware",
# serve static assets in production
"whitenoise.middleware.WhiteNoiseMiddleware",
# provide security enhancements to the request/response cycle

View file

@ -0,0 +1,17 @@
"""Middleware to add Cache-control: no-cache to every response.
Used to force Cloudfront caching to leave us alone while we develop
better caching responses.
"""
class NoCacheMiddleware:
"""Middleware to add a single header to every response."""
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
response = self.get_response(request)
response["Cache-Control"] = "no-cache"
return response