-
Notifications
You must be signed in to change notification settings - Fork 190
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
Backwards Compatibility issue: remove chunked encoding support from WebOb (unless explicitly flagged by WSGI server) #279
Comments
/cc: @mmerickel @jd @mcdonc |
There is already an issue open regarding |
What I would like to do, to give control back to the user ultimately, is ship a piece of middleware that can easily be loaded into the users WSGI pipeline that tells WebOb it is safe to consume This way even if there is no way to check that a server supports |
ISTM that https://gist.github.com/mitsuhiko/5721547 is already implemented in werkzeug and the only issue is that no WSGI servers (I checked werkzeug, waitress, wsgiref, gevent, gunicorn, uwsgi) actually define So if I understand this correctly, if you update webob to depend on |
Yes. Unfortunately due to PEP3333 not properly defining requirements the Content-Length is the only way to know that a request has a body. The only time a client doesn't send a Content-Length is if the request is chunked, in the case of a HTTP -> WSGI the HTTP server is expected to buffer the full chunked request and then pass the WSGI application the full buffered request and set the Content-Length into the environ. Graham Dumpleton on Twitter suggested creating a wsgi.org proposal instead of just an ad-hoc My other proposal is to add a middleware to WebOb that sets |
To me, it seems like adding support for |
Yeah, Graham said something similar about web-sig. I was going to just submit it, let others fight about it. Shipping code wins. As a reminder to myself, need to make sure I support what Graham has in mod_wsgi as well, there is a flag that is set if the user turned on Chunked support. |
This request will send empty body (Content-Length: 0) And according to this note in pep 3333
this line should return immediately: It it hangs, then it is just a little but in wsgiref |
If client is using Chunked Encoding, there should be header "Transfer-Encoding: chunked" in request, and .read() will block until client send a chunk. What exactly wrong with it? |
@redixin The way Also, the WSGI spec does not allow for Hop-by-Hop headers, which is what Sorry, this feature has been removed, and I am not currently interested in re-visiting it, especially with all of the information that is available above! |
The problem with loosely defined specs
Unfortunately the WSGI spec does not have a good way to allow Chunked Encoding if you read the spec loosely. This is an issue because to support it you need to read all of the "should"'s as "must".
That would have been the correct thing to do anyway, but alas we are stuck with what we've got for now.
For example, to showcase the issue:
With:
Will cause the server to hang forever as long as the client keeps the connection open.
env['wsgi.input']
should be file like (i.e. have read/readline) (See PEP-3333)See: https://www.python.org/dev/peps/pep-3333/#input-and-error-streams
However,
wsgiref
will pass the underlying file descriptor for the socket the client is connected to through towsgi.input
in theenviron
.This means when you call
.read()
without aCONTENT_LENGTH
, which may happen if the client is using Chunked Encoding (and WebOb tries its best to support that), then you and up hanging forever.Good servers like waitress don't do this, and we can always call
read()
onwsgi.input
without causing any issues, however it's not guaranteed.Proposal
Choice number One (arguably the most correct choice)
Currently WebOb tries to be too smart for it's own good and that gets it into trouble...
I'd like to turn back the clock, remove any and all support for Chunked Encoding unless there is a flag in the environment that states it is supported. #278 is one such proposal.
mod_wsgi
has another way, potentially add some helper functions that find/validate the environment is right and then automatically enable Chunked Encoding. However if the server doesn't support it, then Chunked Encoding is completely dropped and the only way that WebOb will read fromwsgi.input
will be if there is aCONTENT_LENGTH
set in the environment.There have been previous reported issues with wsgiref's WSGI implementation:
#233, #116
Choice number Two
We completely ignore
wsgiref
, remove the limitations that were added in https://bitbucket.org/ianb/webob/issues/6 (ee7f027) and simply call.read()
unconditionally if there is noCONTENT_LENGTH
to limit us to.I don't know of a good way of verifying if we are running under
wsgiref
or not to warn users of WebOb though.Issues
Chunked encoding is apparently being used more and more by mobile clients, versus your run off the mill browser, but I imagine it has other uses too. While I am loathe to remove support for something, I do believe it should be better implemented. I'd like to allow a request body on all request methods (spec says it's allowed, just doesn't have any defined semantics) but I don't want to break WebOb on servers that don't implement PEP-3333 fully.
While
wsgiref
is the easiest to point out as being faulty, I am not sure choice number two is a good idea simple because there may be other WSGI servers that are not spec compliant...I'd love feedback on this, and ideas on how to move this forward.
Related: #274, #233, #116, #278
The text was updated successfully, but these errors were encountered: