def process_response(self, request, response): """ This removes the ``Vary: Cookie`` header prior to running the standard Django ``UpdateCacheMiddleware.process_response()`` and adds the header back after caching so that in-browser caches are aware to vary the cache on cookies. """ drop_vary_headers(response, ['Cookie']) response = super(PatchedVaryUpdateCacheMiddleware, self).process_response(request, response) patch_vary_headers(response, ['Cookie']) return response
def test_drop_vary_headers(self): response = HttpResponse() self.assertFalse(response.has_header('Vary')) patch_vary_headers(response, ['Cookie']) self.assertTrue(response.has_header('Vary')) self.assertEqual(response['Vary'], 'Cookie') patch_vary_headers(response, ['Nomnomnom']) self.assertEqual(response['Vary'], 'Cookie, Nomnomnom') drop_vary_headers(response, ['Cookie']) self.assertEqual(response['Vary'], 'Nomnomnom') drop_vary_headers(response, ['Nomnomnom']) self.assertFalse(response.has_header('Vary'))