#7535 closed (fixed)
django.views.static.serve does not properly set Content-Encoding header
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Generic views | Version: | dev |
Severity: | Keywords: | content-encoding static view development manage.py | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
Amidst trying to gzip a javascript file, I noted that the interaction between my browser (FF3/Linux) and the manage.py server only showed me the compressed version of the requested file. I believe it's due to not properly setting the Content-Encoding header.
This patch adds the Content-Encoding header to django.views.static.serve as returned by mimetypes.guess_type .
Attachments (3)
Change History (15)
by , 16 years ago
Attachment: | static.py.patch added |
---|
comment:1 by , 16 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 16 years ago
Patch needs improvement: | set |
---|
The patch will break if mimetypes cannot guess the content type or the encoding. Specifically this expression:
mimetypes.guess_type(fullpath) or mimetype
will never use the second mimetype variable since .guess_type() returns a 2-tuple which has a boolean value of True.
It is easier (albeit a little longer) to check both content-type and -encoding separately for None and use appropriate fallbacks.
by , 16 years ago
Attachment: | static.py.2.patch added |
---|
Content-Encoding patch for django.views.static.serve, revision 2
comment:3 by , 16 years ago
Heh, length I am not worried about; I'm just learning. For whatever reason, mimetypes and encodings confuse me. In any event, I was attempting to follow the "compressed" look of the code.
Does this second revision of the patch work then?
follow-up: 5 comment:4 by , 16 years ago
The patch looks ok. You can shorten the code a bit by assigning a tuple to multiple variables:
mimetype, encoding = mimetypes.guess_type(fullpath) if mimetype is None: mimetype = 'application/octet-stream'
comment:5 by , 16 years ago
Ah cool, and even one more line?
mimetype = mimetype or 'application/octet-stream'
comment:7 by , 16 years ago
Is this patch good then? I note the "Patch needs improvement" bit is still set so is there anything else I need to do while this is still fresh in my mind? Should I submit .3 of the patch with minification discussed?
follow-up: 9 comment:8 by , 16 years ago
Yes, add a .3 patch (or replace the .2 one) and delete the improvement checkbox. Thanks for the work.
by , 16 years ago
Attachment: | static.py.3.patch added |
---|
Content-Encoding patch for django.views.static.serve, revision 3, hopefully final
comment:9 by , 16 years ago
Patch needs improvement: | unset |
---|
Alright, thar she blows. v3, hopefully final patch, added. Pleasure doin' business with ya.
comment:10 by , 14 years ago
Patch needs improvement: | set |
---|
Patch needs to be ported to current version of source:/django/trunk/django/views/static.py.
comment:11 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Content-Encoding patch for django.views.static.serve