CommonMiddleware ETag processing doesn't work as expected

49 views
Skip to first unread message

Oleksiy Ivanenko

unread,
Feb 26, 2016, 6:35:40 AM2/26/16
to Django users
Hello!

I'm trying to use django.middleware.common.CommonMiddleware to set ETags and it seems to me, that I found a bug.

if settings.USE_ETAGS:
   
if not response.has_header('ETag'):
        set_response_etag
(response)

   
if response.has_header('ETag'):
       
return get_conditional_response(  # always returns response with 200 code
            request
,
            etag
=response['ETag'],
            response
=response,
       
)

Actual result:
django.utils.cache.get_conditional_response Always returns original response, even if ETag from header corresponds to ETag of current content.

Expected result:
django.utils.cache.get_conditional_response Must return HttpResponseNotModified response with 304 status, if ETag from header corresponds to ETag of current content.

I think the reason of such behaviour:
  1. etag argument passes to get_conditional_response as quoted string (as specified in RFC). For example: '"281abb9608fa10d8839e5e8df5c98b0b"'
  2. Inside get_conditional_response etags list is parsed from headers as list of unquoted strings. For example: ['281abb9608fa10d8839e5e8df5c98b0b']
  3. Then etag in etags check allways returns False!

Is it a bug, or expected?

Denis Cornehl

unread,
Feb 26, 2016, 7:19:23 AM2/26/16
to django...@googlegroups.com
Hi Oleksiy, 

what version of Django are you using? 

There was a bug:
fixed here

which was released in Django 1.9.2 



-- 
Freundliche Grüße

Denis Cornehl
Sonntagstr. 2 / 10245 Berlin

M: +49 (151) 25 25 1450


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4a0fbb44-9c3b-4223-97d9-b9c41fa3d445%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Oleksiy Ivanenko

unread,
Feb 26, 2016, 8:22:31 AM2/26/16
to Django users
Hi Denis,

I'm using django 1.9
Thanks for issue and PR links. It seems reasonable now to upgrade to django 1.9.2 :)
Reply all
Reply to author
Forward
0 new messages