SVN: r24962 - trunk/quixote
Neil Schemenauer <nascheme-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Fri, 20 Aug 2004 12:03:40 -0400
| Newsgroups | gmane.comp.web.quixote.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: nascheme
Date: 2004-08-20 12:03:03 -0400 (Fri, 20 Aug 2004)
New Revision: 24962
Modified:
trunk/quixote/http_response.py
Log:
Add 'buffered' flag to HTTPResponse (defaulting to True).
Modified: trunk/quixote/http_response.py
===================================================================
--- trunk/quixote/http_response.py 2004-08-19 20:40:17 UTC (rev 24961)
+++ trunk/quixote/http_response.py 2004-08-20 16:03:03 UTC (rev 24962)
@@ -103,6 +103,12 @@
"Content-type" or "Content-length" headers. These headers
are set as soon as the body is set (with set_body()), even
if the body is an empty string.
+ buffered : bool
+ if false, response data will be flushed as soon as it is
+ written (the default is true). This is most useful for
+ responses that use the Stream() protocol. Note that whether the
+ client actually receives the partial response data is highly
+ dependent on the web server
cookies : { name:string : { attrname : value } }
collection of cookies to set in this response; it is expected
that the user-agent will remember the cookies and send them on
@@ -134,6 +140,7 @@
self.cookies = {}
self.cache = 0
+ self.buffered = 1
self.javascript_code = None
def set_status (self, status, reason=None):
@@ -375,6 +382,7 @@
# "non-parsed header" mode, where the CGI script is responsible
# for generating a complete HTTP response with no help from the
# server.
+ flush_output = not self.buffered and hasattr(file, 'flush')
for name, value in self.generate_headers():
file.write("%s: %s\r\n" % (name, value))
file.write("\r\n")
@@ -382,8 +390,12 @@
if isinstance(self.body, Stream):
for chunk in self.body:
file.write(chunk)
+ if flush_output:
+ file.flush()
else:
file.write(self.body)
+ if flush_output:
+ file.flush()
class Stream: