Support chunked encoding - #21
Conversation
coordt
left a comment
There was a problem hiding this comment.
I like this change.
I would like to see some documentation for it in the readme, but the code looks fine.
|
Ah yeah, good call. I'll add a mention of it. At some point I think it'd be nice to split out the documentation into separate files and use Sphinx to generate proper package documentation which we can then upload to ReadTheDocs, leaving the README for the basics, like installation instructions and the simplest possible usage example. But that's a whole separate discussion. |
|
I was actually just looking at the existing commented-out test case for gzip compression and I noticed it uses an attribute of @redtoad if you have the chance, maybe you can comment on how intentional that decision was in the gzip case? (to use an attribute of Aside from code clarity, the only functional advantage I can think of to using an attribute is that it allows clients to test whether they handle incorrectly encoded HTTP responses, like if a server applies chunking but doesn't set the |
If memory serves right I wanted to explicitly turn compression on/off and not base it on the request header. Maybe that would something for an "enum": YES, NO, AUTO (i.e. if requested via header) |
|
Good idea, I'll change it accordingly. |
e9a355a to
4abe099
Compare
|
I've implemented the version with the enum; thanks for that suggestion 😄 It breaks compatibility with Python 2.7 and 3.3, because the |
4abe099 to
5867269
Compare
5867269 to
d20ddae
Compare
|
I've been trying this out in a private project and am getting a weird bug that is probably due to the other project's code, but I'm not sure. I'm hoping to get to the bottom of it before merging this, just in case there's an issue with the chunked encoding handling here. |
This allows passing an iterable of strings or bytes to serve_content() so that it can be returned using chunked encoding.
This allows case-insensitive matching of header names.
This commit adds an implementation of chunk encoding to ContentServer. The decision of whether to apply chunking is controlled by an enum, which takes values YES (apply chunking), NO (don't apply chunking), or AUTO (apply chunking only if requested by the Transfer-Encoding header). I set the default value of the flag to NO for backwards compatibility, but it could be changed to AUTO in the future, which would probably make more sense.
This commit adds several test cases that confirm the server is able to send data using the chunked transfer encoding, that it correctly does or doesn't apply chunking depending on the value of the chunked attribute and the Transfer-encoding header, that the Content-length header is correctly omitted when sending a chunked response, and that various combinations of content size and chunk size work correctly.
d20ddae to
1ae3d6d
Compare
I came up with this patch set a while ago for another project of mine that was experiencing errors only when receiving chunk-encoded data. It adds the ability to serve a chunked response. I know that users can do this themselves using a custom WSGI application, but since chunking is a part of the HTTP 1.1 standard, it's a common enough use case that it might be reasonable to handle it directly.
I'd be curious for your opinions @redtoad and @coordt about whether this makes sense to add to the project.