Update existing vary headers in response instead of overwriting them.

Previously, any existing vary headers would simply be wiped out by DRF. Using patch_vary_headers assures that existing headers remain.
This commit is contained in:
Robert Kirberich 2017-04-04 13:57:19 +01:00
parent 5e6b233977
commit 9ebd5a29e4

View File

@ -9,6 +9,7 @@ from django.db import models
from django.http import Http404
from django.http.response import HttpResponseBase
from django.utils import six
from django.utils.cache import cc_delim_re, patch_vary_headers
from django.utils.encoding import smart_text
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.csrf import csrf_exempt
@ -414,6 +415,11 @@ class APIView(View):
response.accepted_media_type = request.accepted_media_type
response.renderer_context = self.get_renderer_context()
# Add new vary headers to the response instead of overwriting.
vary_headers = self.headers.pop('Vary', None)
if vary_headers is not None:
patch_vary_headers(response, cc_delim_re.split(vary_headers))
for key, value in self.headers.items():
response[key] = value