Opened 12 years ago
Closed 12 years ago
#18675 closed Bug (fixed)
If-modified-since for static resources not working.
Reported by: | Piotr Czachur | Owned by: | Simon Charette |
---|---|---|---|
Component: | HTTP handling | Version: | dev |
Severity: | Normal | Keywords: | static serve |
Cc: | charette.s@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
How to reproduce
- Enable serving static files.
- Request same file multiple times.
- You always get HTTP "200", but it should be "304" after first request.
What causes the problem
django.views.static.was_modified_since() compares modification time taken from two sources:
- os.stat()
- HTTP_IF_MODIFIED_SINCE header.
os.stat() returns timestamp as float (Linux 64bit), and header contains integer timestamp, which results in such comparsions for unmodified files:
if 1331113576.68 > 1331113576: // assuming file was modified
which have incorrect result.
was_modified_since() should refuse comparing values of different types, or cast both to integers.
Notice that values returned by os.stat() can be OS-dependent.
Attachments (1)
Change History (7)
comment:1 by , 12 years ago
Keywords: | static serve added |
---|---|
Owner: | changed from | to
Triage Stage: | Unreviewed → Accepted |
Version: | 1.4 → master |
by , 12 years ago
Attachment: | 0001-18675.patch added |
---|
comment:3 by , 12 years ago
Easy pickings: | set |
---|---|
Triage Stage: | Accepted → Ready for checkin |
is header_mtime always generated in a way that it is an int - or should it be cast at comparison time as well?
given that small caveat - I'd say this is RFC, I verified tests, and really far more people are using static serve in production behind things like gunicorn on heroku now.
comment:4 by , 12 years ago
Cc: | added |
---|
Looking at the code behind `djangp.utils.http.parse_http_date` it seems that header_mtime
can only be an int
since it returns the number of seconds since epoch from a datetime
with no considerations towards units of magnitude lesser than seconds.
However the docstring clearly states: Returns an[sic] floating point number expressed in seconds since the epoch, in UTC
I think the parse_http_date
's docstring should be changed and it's return result also cast to int
?
comment:6 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Running Linux 64 bit myself I can confirm
os.stat
returns a float. I'll write a patch with a failing testcase.I guess no-one stumbled upon this issue since
serve
is only meant to be used in development.