diff options
| author | Kevin Christopher Henry <k@severian.com> | 2016-10-11 00:08:37 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-10-12 14:43:25 -0400 |
| commit | bd7237d7ec5bb66add624a0cf31ac85f9aceadce (patch) | |
| tree | 467b143b109161093901358b01171fff756d872a /django | |
| parent | b2f9db1637021f5a0a0c201017f6536243ed203f (diff) | |
Fixed #19705 -- Set proper headers on conditional Not Modified responses.
Diffstat (limited to 'django')
| -rw-r--r-- | django/utils/cache.py | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/django/utils/cache.py b/django/utils/cache.py index 8d0ce4dac5..0f6232b51b 100644 --- a/django/utils/cache.py +++ b/django/utils/cache.py @@ -122,14 +122,21 @@ def _precondition_failed(request): def _not_modified(request, response=None): + new_response = HttpResponseNotModified() if response: - # We need to keep the cookies, see ticket #4994. - cookies = response.cookies - response = HttpResponseNotModified() - response.cookies = cookies - return response - else: - return HttpResponseNotModified() + # Preserve the headers required by Section 4.1 of RFC 7232, as well as + # Last-Modified. + for header in ('Cache-Control', 'Content-Location', 'Date', 'ETag', 'Expires', 'Last-Modified', 'Vary'): + if header in response: + new_response[header] = response[header] + + # Preserve cookies as per the cookie specification: "If a proxy server + # receives a response which contains a Set-cookie header, it should + # propagate the Set-cookie header to the client, regardless of whether + # the response was 304 (Not Modified) or 200 (OK). + # https://curl.haxx.se/rfc/cookie_spec.html + new_response.cookies = response.cookies + return new_response def get_conditional_response(request, etag=None, last_modified=None, response=None): |
