Opened 16 years ago
Closed 13 years ago
#10762 closed Cleanup/optimization (fixed)
Gzip Middleware Should Compress 201 (Created) Responses
Reported by: | Owned by: | Aymeric Augustin | |
---|---|---|---|
Component: | HTTP handling | Version: | dev |
Severity: | Normal | Keywords: | middleware gzip |
Cc: | Georges Dubus, Aaron Cannon | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
Hi,
RESTful web services that use POST for creation of resources often respond with a representation of the newly created resource, which can be lengthy. However, the appropriate status code is 201, which the Gzip middleware ignores. There's a trivial patch attached that contains these lines:
- if response.status_code != 200 or len(response.content) < 200: + if response.status_code not in (200, 201) or len(response.content) < 200:
This is not a particularly big deal, just a convenience.
Thanks,
Rick
Attachments (3)
Change History (14)
by , 16 years ago
Attachment: | gzip.patch added |
---|
follow-up: 2 comment:1 by , 16 years ago
comment:2 by , 16 years ago
Replying to julianb:
While we are at it: What about 404 or 403 responses?
I don't believe that was what was intended by the original condition. The 2XX status codes indicate successful operations, whereas 4XX are client errors. In practice, I think it is a good idea to render errors in the simplest formats possible, to make interpreting them easier on the client side. But, I can see the argument for compressing a custom 404 response that is rendered from a template, and could get large.
--Rick
comment:3 by , 15 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:4 by , 14 years ago
The comment in gzip.py
say: "It's not worth compressing non-OK or really short responses."
If non-OK responses are not worth compressing because they are expected to be short, testing their length is enough, which means the check on response.status_code
should be removed.
If there is another reason why non-OK responses should not be compressed, the proper check is 200 <= response.status_code < 300
, and the reason should be explained in a comment.
comment:5 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Cleanup/optimization |
by , 14 years ago
Attachment: | 10762.patch added |
---|
comment:6 by , 14 years ago
Easy pickings: | unset |
---|
Regarding Rick's comment above: the content will only be gzipped if the user agent sent an Accept-Encoding: gzip
header. It seems reasonable to assume it will be able to decode gzip, even if the server returns an error page.
comment:7 by , 13 years ago
Easy pickings: | set |
---|---|
Needs tests: | set |
Triage Stage: | Design decision needed → Accepted |
UI/UX: | unset |
comment:8 by , 13 years ago
Cc: | added |
---|---|
Needs tests: | unset |
Here are simple tests to check that long responses are compressed and short responses are not, regardless of the return type. Are they ok ?
comment:9 by , 13 years ago
Cc: | added |
---|
While we are at it: What about 404 or 403 responses?