def set_hsts_header(self, response): """ Adds HSTS header to each response. """ if request.is_secure: response.headers.setdefault('Strict-Transport-Security', self.hsts_header) return response