[Web-SIG] When must applications call the WSGI start_response callable.

James Y Knight foom at fuhm.net
Thu Dec 15 21:29:00 CET 2005


On Dec 15, 2005, at 3:01 PM, Jim Fulton wrote:
> Normally an application will call the start_response callable when the
> application is called or when the result iterator is constructed, as
> shown in the first 2 examples. An application, or more commonly, a
> middleware component that provides it's own thread management might
> delay starting the response.  A server should not begin iterating
> over the result until the start_response callable has been called."

But it's my understanding that this is valid:

     def test_calledStartResponseLate(self):
         def application(environ, start_response):
             start_response("200 OK", {})
             yield "Foo"

start_response is called _inside_ the first iteration of the result.  
So the server has to iterate at least once, even if start_response  
was not called...

I was led to believe this was a valid thing to do from the following  
wording:
> (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.)

James


More information about the Web-SIG mailing list