Friday, February 26, 2016

Re: CommonMiddleware ETag processing doesn't work as expected

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
@: denis.cornehl@gmail.com

http://www.for-a-faster-web.com

Am Freitag, 26. Februar 2016 um 12:35 schrieb Oleksiy Ivanenko:

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?

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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/C97C65589BA74D19BDF188AE0545912D%40fastmail.fm.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment