[Web-SIG] WSGI 2

Robert Brewer fumanchu at aminus.org
Tue Aug 4 21:10:09 CEST 2009


James Bennett wrote:
> On Tue, Aug 4, 2009 at 11:54 AM, James Y Knight<foom at fuhm.net> wrote:
>> But that works just fine today. Your WSGI app sends streaming data back
>> using the iterator functionality, and the server automatically turns it into
>> chunks if it's talking to an HTTP 1.1 client. What's the problem?
> 
> No, it doesn't work just fine today. Either the server has to assume
> that every response from that application should be chunked (which is
> wrong), or the application needs a way to tell the server to chunk.
> Turns out HTTP has a way to indicate that, but WSGI outright forbids
> its use. So instead you have to invent out-of-band mechanisms for the
> application to tell the server what to do, and in the process reinvent
> part of HTTP.

It doesn't have to be out of band; CherryPy's wsgiserver will send a response chunked if the application provides no Content-Length response header.

if status == 413:
    # Request Entity Too Large. Close conn to avoid garbage.
    self.close_connection = True
elif "content-length" not in hkeys:
    # "All 1xx (informational), 204 (no content),
    # and 304 (not modified) responses MUST NOT
    # include a message-body." So no point chunking.
    if status < 200 or status in (204, 205, 304):
        pass
    else:
        if self.response_protocol == 'HTTP/1.1':
            # Use the chunked transfer-coding
            self.chunked_write = True
            self.outheaders.append(("Transfer-Encoding", "chunked"))
        else:
            # Closing the conn is the only way to determine len.
            self.close_connection = True


Robert Brewer
fumanchu at aminus.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/web-sig/attachments/20090804/00001283/attachment-0001.htm>


More information about the Web-SIG mailing list