If-modified-since for static resources not working.
|Reported by:||zimnyx||Owned by:||charettes|
|Cc:||charette.s@…||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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:
- 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.
Change History (7)
comment:1 Changed 4 years ago by charettes
- Keywords static serve added
- Needs documentation unset
- Needs tests unset
- Owner changed from nobody to charettes
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted
- Version changed from 1.4 to master
Changed 4 years ago by charettes
comment:2 Changed 4 years ago by charettes
- Has patch set
comment:3 Changed 4 years ago by ptone
- Easy pickings set
- Triage Stage changed from Accepted to Ready for checkin