diff options
| author | Denis Cornehl <syphar@fastmail.fm> | 2016-01-05 08:09:10 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-01-05 09:41:13 -0500 |
| commit | ee2835e69c47d02e8bce5a496bf8bd9f93b04fb4 (patch) | |
| tree | dccba382988875d2e87f531f3042dba24df7e643 /django | |
| parent | 775291d4c767cd17dc5bbd2e8a605fd4fdfd8aed (diff) | |
[1.9.x] Fixed #26024 -- Fixed regression in ConditionalGetMiddleware ETag support.
Backport of 186b6c61bfe85afa4d6bf213d04a28dd2853fed2 from master
Diffstat (limited to 'django')
| -rw-r--r-- | django/middleware/common.py | 5 | ||||
| -rw-r--r-- | django/middleware/http.py | 4 | ||||
| -rw-r--r-- | django/utils/http.py | 7 |
3 files changed, 11 insertions, 5 deletions
diff --git a/django/middleware/common.py b/django/middleware/common.py index 3db925c894..a8958a80e3 100644 --- a/django/middleware/common.py +++ b/django/middleware/common.py @@ -8,6 +8,7 @@ from django.core.exceptions import PermissionDenied from django.core.mail import mail_managers 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, ) diff --git a/django/middleware/http.py b/django/middleware/http.py index 7a6f237c96..7912200634 100644 --- a/django/middleware/http.py +++ b/django/middleware/http.py @@ -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, ) diff --git a/django/utils/http.py b/django/utils/http.py index 8bbafaedec..70bcbd90ac 100644 --- a/django/utils/http.py +++ b/django/utils/http.py @@ -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 |
