[Python-Dev] wsgi validator with asynchronous handlers/servers (original) (raw)
Luca Sbardella luca.sbardella at gmail.com
Sat Mar 23 20:05:32 CET 2013
- Previous message: [Python-Dev] Are undocumented exceptions considered bugs?
- Next message: [Python-Dev] wsgi validator with asynchronous handlers/servers
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi,
I have an asynchronous wsgi application handler which yields empty bytes before it is ready to yield the response body and, importantly, to call start_response.
Something like this:
def wsgi_handler(environ, start_response): body = generate_body(environ) body = maybe_async(body) while is_async(body): yield b'' start_response(...) ...
I started using wsgiref.validator recently, nice little gem in the standard lib, and I discovered that the above handler does not validate! Disaster. Reading pep 3333
"the application must invoke the start_response() callable before the iterable yields its first body bytestring, so that the server can send the headers before any body content. However, this invocation may be performed by the iterable's first iteration, so servers must not assume that start_response() has been called before they begin iterating over the iterable."
The pseudocode above does yields bytes before start_response, but they are not body bytes, they are empty bytes so that the asynchronous wsgi server releases the eventloop and call back at the next eventloop iteration.
I'm I misinterpreting the pep, or the wsgi validator should be fixed accordingly?
Regards, Luca -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20130323/20d85ed7/attachment.html>
- Previous message: [Python-Dev] Are undocumented exceptions considered bugs?
- Next message: [Python-Dev] wsgi validator with asynchronous handlers/servers
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]