mirror of
https://github.com/django/django.git
synced 2025-10-26 07:06:08 +00:00
Fixed #26024 -- Fixed regression in ConditionalGetMiddleware ETag support.
Thanks Denis Cornehl for help with the patch.
This commit is contained in:
committed by
Tim Graham
parent
d5b90c8e12
commit
186b6c61bf
@@ -8,6 +8,7 @@ from django.core.mail import mail_managers
|
||||
from django.urls import is_valid_path
|
||||
from django.utils.cache import get_conditional_response, set_response_etag
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.http import unquote_etag
|
||||
from django.utils.six.moves.urllib.parse import urlparse
|
||||
|
||||
logger = logging.getLogger('django.request')
|
||||
@@ -120,9 +121,7 @@ class CommonMiddleware(object):
|
||||
if response.has_header('ETag'):
|
||||
return get_conditional_response(
|
||||
request,
|
||||
# get_conditional_response() requires an unquoted version
|
||||
# of the response's ETag.
|
||||
etag=response['ETag'].strip('"'),
|
||||
etag=unquote_etag(response['ETag']),
|
||||
response=response,
|
||||
)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from django.utils.cache import get_conditional_response
|
||||
from django.utils.http import http_date, parse_http_date_safe
|
||||
from django.utils.http import http_date, parse_http_date_safe, unquote_etag
|
||||
|
||||
|
||||
class ConditionalGetMiddleware(object):
|
||||
@@ -23,7 +23,7 @@ class ConditionalGetMiddleware(object):
|
||||
if etag or last_modified:
|
||||
return get_conditional_response(
|
||||
request,
|
||||
etag=etag,
|
||||
etag=unquote_etag(etag),
|
||||
last_modified=last_modified,
|
||||
response=response,
|
||||
)
|
||||
|
||||
@@ -253,6 +253,13 @@ def quote_etag(etag):
|
||||
return '"%s"' % etag.replace('\\', '\\\\').replace('"', '\\"')
|
||||
|
||||
|
||||
def unquote_etag(etag):
|
||||
"""
|
||||
Unquote an ETag string; i.e. revert quote_etag().
|
||||
"""
|
||||
return etag.strip('"').replace('\\"', '"').replace('\\\\', '\\') if etag else etag
|
||||
|
||||
|
||||
def is_same_domain(host, pattern):
|
||||
"""
|
||||
Return ``True`` if the host is either an exact match or a match
|
||||
|
||||
Reference in New Issue
Block a user