[Web-SIG] a possible error in the WSGI spec

Phillip J. Eby pje at telecommunity.com
Thu Dec 20 17:43:58 CET 2007


At 01:27 PM 12/20/2007 +0100, Manlio Perillo wrote:
>Hi.
>
>It seems that there is a little error in the WSGI spec.
>
>In the "Specification Details" chapter there is this note:
>
>"""(Note: the application must invoke the start_response() callable
>before the iterable yields its first body string, 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.)"""
>
>
>What's wrong is that the invocation of start_response may be performed
>at any iteration of the iterable, as long as the application yields
>empty strings.

You're right - the intent here was before the iterable yields its 
first non-empty body string.


>There is also a little problem in the "The start_response() Callable"
>chapter, in this phrase:
>
>"""The start_response callable must not actually transmit the response
>headers. Instead, it must store them for the server or gateway to
>transmit only after the first iteration of the application return value
>that yields a non-empty string, or upon the application's first
>invocation of the write() callable"""
>
>
>  From this it seems that the response headers should be transmitted
>after the first invocation of the write() callable, even if it returns
>an empty string, but this is in contradiction with the following phrase:
>
>"""In other words, response headers must not be sent until there is
>actual body data available, or until the application's returned iterable
>is exhausted"""

There is no sane reason to call write() with an empty string, so I 
don't really see a conflict here.

Please note that both write() and iteration in the normal case should 
be sending the entire response body in a single call or 
yield.  Multiple yields or write() calls should ONLY be used when 
streaming output is *required*: i.e. server push or sending large files.

(In addition, write() is intended strictly for legacy apps and 
frameworks only; new code should use iteration only, especially as 
WSGI 2 will drop the start_response() and write() functions altogether.)



More information about the Web-SIG mailing list