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 wsgi.input_terminated flag #1664

Closed
davidism opened this Issue Nov 28, 2017 · 4 comments

Comments

Projects
None yet
2 participants
@davidism

davidism commented Nov 28, 2017

(Assuming CherryPy supports chunked transfer encoding, I'm not directly familiar with this WSGI server / client.) Unfortunately the WSGI spec has no support for it. A standard was proposed by @mitsuhiko here: https://gist.github.com/mitsuhiko/5721547. If the WSGI server supports streams without a content length, it should set environ['wsgi.input_terminated'] = True. If a WSGI client sees this flag, it can ignore the content length and read the stream as-is. Other servers and clients are starting to support this.

@webknjaz

This comment has been minimized.

Member

webknjaz commented Dec 2, 2017

@davidism CherryPy already ignores Content-Length in case of chunked transfer encoding: https://github.com/cherrypy/cherrypy/blob/9d95d40/cherrypy/_cpreqbody.py#L449

Also, the whole WSGI/HTTP layer has been moved to separate repo Cheroot a while ago. So the issue looks related to that project, not CherryPy itself.

@jaraco do you have any insights on this?

@webknjaz

This comment has been minimized.

Member

webknjaz commented Dec 2, 2017

@davidism

This comment has been minimized.

davidism commented Dec 2, 2017

The idea is for the server to be able to communicate to the client that the input is already terminated. So if someone wants to use the CherryPy WSGI server for their Flask app (an example I come across occasionally), Flask (Werkzeug) knows it can safely read the stream even though there's no content length.

It looks like CherryPy assumes the WSGI server will terminate input correctly, but this isn't the case for all servers. This proposal gives us a way for the server to explicitly state that it is safe to read the stream without a length, instead of the client needing to make assumptions.

In CherryPy's case, if cheroot handles reading chunked encoding, it should set wsgi.input_terminated = True. Then in CherryPy instead of looking at Transfer-Encoding, look at wsgi.input_terminated.

webknjaz added a commit to cherrypy/cheroot that referenced this issue Dec 2, 2017

Signal WSGI app that the input is terminated
Sets ``env['wsgi.input_terminated'] = True`` if the request uses
chunked Transfer-Encoding, so that WSGI app would know that it's safe
to read from ``env['wsgi.input']`` stream.

Implements @mitsuhiko's proposal:
https://gist.github.com/mitsuhiko/5721547

Ref: cherrypy/cherrypy#1664
Ref: Pylons/webob#278
Ref: unbit/uwsgi#1428
@webknjaz

This comment has been minimized.

Member

webknjaz commented Dec 2, 2017

@davidism Does cherrypy/cheroot#66 look okay to you?

webknjaz added a commit to cherrypy/cheroot that referenced this issue Dec 2, 2017

Signal WSGI app that the input is terminated
Sets ``env['wsgi.input_terminated'] = True`` if the request uses
chunked Transfer-Encoding, so that WSGI app would know that it's safe
to read from ``env['wsgi.input']`` stream.

Implements @mitsuhiko's proposal:
https://gist.github.com/mitsuhiko/5721547

Ref: cherrypy/cherrypy#1664
Ref: Pylons/webob#278
Ref: unbit/uwsgi#1428
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment