Opened 16 years ago

Closed 16 years ago

#7046 closed (fixed)

ConditionalGetMiddleware doesn't set response code properly

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

Description

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/http.py:

        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 16 years ago.

Download all attachments as: .zip

Change History (4)

comment:1 by Eratothene, 16 years ago

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

by Simon Greenhill, 16 years ago

Attachment: 7046.diff added

comment:2 by Simon Greenhill, 16 years ago

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 by Malcolm Tredinnick, 16 years ago

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