"""
No-cache middleware — forces every HTML response to carry Cache-Control
no-store headers so the PDA WebView never serves a stale copy.
"""
from django.utils.deprecation import MiddlewareMixin


class NoCacheMiddleware(MiddlewareMixin):
    def process_response(self, request, response):
        ctype = response.get('Content-Type', '')
        if 'text/html' in ctype or 'application/xhtml' in ctype:
            response['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0, private'
            response['Pragma'] = 'no-cache'
            response['Expires'] = '0'
        return response
