Opened 10 years ago

Closed 10 years ago

#7046 closed (fixed)

ConditionalGetMiddleware doesn't set response code properly

Reported by: DOP Owned by: nobody
Component: Core (Other) Version: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Just noticed that If-None-Match request doesn't really work even though ConditionalGetMiddleware is enabled and the response has ETag matching If-None-Match header in the request.

This is from django/middleware/

        if response.has_header('ETag'):
            if_none_match = request.META.get('HTTP_IF_NONE_MATCH', None)
            if if_none_match == response['ETag']:
                response.status = 304

        if response.has_header('Last-Modified'):
            if_modified_since = request.META.get('HTTP_IF_MODIFIED_SINCE', None)
            if if_modified_since == response['Last-Modified']:
                response.status = 304

Shouldn't it be response.status_code = 304?

Attachments (1)

7046.diff (951 bytes) - added by Simon Greenhill 10 years ago.

Download all attachments as: .zip

Change History (4)

comment:1 Changed 10 years ago by Eratothene

I have just checked it. Indeed it should be response.status_code = 304

Changed 10 years ago by Simon Greenhill

Attachment: 7046.diff added

comment:2 Changed 10 years ago by Simon Greenhill

Has patch: set
Triage Stage: UnreviewedReady for checkin

Yep, should be status_code. I think what's happened is that the Request/Response attribute is status_code, the parameter given to set it in __init__ is status, which has confused the person who added that code (it certainly confused me - I've opened #7453 to track this additional issue.

comment:3 Changed 10 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

(In [7793]) Fixed #7046 -- set the response status code correctly in ConditionalGetMiddleware.

Note: See TracTickets for help on using tickets.
Back to Top