Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions rest_framework/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,18 @@ def get_referenced_base_fields_from_q(q):
}


if django.VERSION >= (6, 1):
# `split_header_value` was added in Django 6.2 (backported to 6.1b1+),
# replacing the `cc_delim_re` regular expression.
# https://github.com/django/django/commit/526b1b414d8e215bf627b5722df12a09346dbf6b
from django.utils.http import split_header_value
else:

def split_header_value(value, sep=","):
for part in value.split(sep):
if stripped := part.strip():
yield stripped

# `separators` argument to `json.dumps()` differs between 2.x and 3.x
# See: https://bugs.python.org/issue22767
SHORT_SEPARATORS = (',', ':')
Expand Down
5 changes: 3 additions & 2 deletions rest_framework/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
from django.db import connections, models
from django.http import Http404
from django.http.response import HttpResponseBase
from django.utils.cache import cc_delim_re, patch_vary_headers
from django.utils.cache import patch_vary_headers
from django.utils.encoding import smart_str
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import View

from rest_framework import exceptions, status
from rest_framework.compat import split_header_value
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.schemas import DefaultSchema
Expand Down Expand Up @@ -444,7 +445,7 @@ def finalize_response(self, request, response, *args, **kwargs):
# 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))
patch_vary_headers(response, split_header_value(vary_headers))
Comment on lines 445 to +448

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@laymonage would you mind cross checking this suggestion?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find any tests that exercise the existing behaviour for reference. Unfortunately I don't have time to set it up and write it myself. I can ask AI to write it if that's acceptable here…

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure no problem


for key, value in self.headers.items():
response[key] = value
Expand Down
Loading