-
-
Notifications
You must be signed in to change notification settings - Fork 16.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support for HTTP/1.1 Transfer-Encoding: chunked #367
Comments
By the way, cherryPy seems to have chunked support (haven't tested it yet), which may give guidance with the implementation. |
WSGI does not support chunked request encodings. There is not much I can do about that. |
Then the consumer should reject the request, instead of trying to parse the body and failing, no? Also, this changelog: http://code.google.com/p/modwsgi/wiki/ChangesInVersion0300 indicates that mod_wsgi, for one, is capable of parsing chunked requests (even though it doesn't support actual buffering of them). |
Werkzeug does not generate responses by itself, that's up for the developer. The question is if we should automatically reject chunked requests in Flask and there I don't know yet. I was always hoping that WSGI servers would advertise their ability to handle chunked requests but it does not seem like there is a consistent way they do that.
Yes. But from the view of Werkzeug I cannot find out if a WSGI server extends the WSGI spec to support chunked requests. And if I assume it does I can cause a timeout on the client. The problem is that WSGI specifies that one should read up to Content-Length. This header is missing if chunked requests are being handled. But then there are two situations. Either the WSGI server unpacks the chunked requests for us and we're good to read from the stream until the stream stops by itself or the WSGI server does not and if we try to do we request too much data from the client and the connection stalls waiting for more bytes that never get transmitted. |
I see, thanks for the explanation. Not happy with WSGI right now :( |
What I could do would be changing werkzeug to listen to a 'werkzeug.support_chunked' environment variable. In that case if the application is hosted on mod_wsgi you can flip that flag with a middleware and it magically starts working. |
That would be great, however I'm using flask on its own as a simple REST API endpoint, putting it on mod_wsgi would surely be overkill. |
Well, CherryPy as a server instead of the builtin one would do the trick as well I guess. Will check that after Christmas. |
Thanks! Flask itself is a joy to work with. |
Let's revisit this.
PEP 333/3333 state
This guarantees that the application will always see a flat decoded stream in "wsgi.input", not chunks. |
Is there an update on this issue? I'm trying to use stream_with_context and was hoping to see the resulting output as chunks instead of as a HTTP 1.0 response without a content-length. |
@zroadhouse-wsm You're following this snippet? I think that snippet (chunked responses) works but this issue is for reading chunked requests from clients. |
Yes - very similar. In my case, I'm waiting for a long running query. Flask is executing behind AWS ELB -> nginx -> uwsgi -> flask. The ELB enforces a 60s timeout and I was hoping to use stream_with_context to transmit content using chunks to keep the connection open while my query executes. My test results calling at each of the layers:
Here's the code snippet I am using for experimenting:
Curl output:
|
Uh... the embedded flask/werkzeug server is not suitable for production. |
@ThiefMaster - If you read my post, you'll see I'm using AWS ELB -> nginx -> uwsgi -> flask -- the example above is part of my debugging exercise. |
Looks like my issue is different from the OP - commented here since this was the only issue mentioning chunked encoding. If anyone can provide a pointer for getting response chunked encoding working, I'd appreciate it. |
The original point mentioned by @mitsuhiko still stands: WSGI by itself does not allow chunked encoding. So there is no pointer to give. |
@mitsuhiko @DasIch I think you guys missed @a13xb's comment...PEP 333 and PEP 3333 explicitly state:
Am I misunderstanding this or does it contradict what you guys have said? |
The WSGI spec unfortunately cannot be implemented with regards to chunked. We have hidden support to dealing with severs can decode it on the fly ( |
You mean something about the design makes it technically impossible to implement official support for chunked encoding? |
I see other people saying things like
Does this mean the WSGI spec contradicts itself? |
I tried to fix this problem a few years back and I introduced a hint called |
I see, strange. Thanks for the tip! |
Flask seems to choke on chunked encoded requests (I've only tried with Content-Type: application/json). This results in an error when parsing the request body (and being able to deal with chunked encoding is a requirement of HTTP 1.1).
The text was updated successfully, but these errors were encountered: