SVN: r25634 - in trunk/quixote: . server

Neil Schemenauer <nascheme-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Wed, 17 Nov 2004 19:06:42 -0500
Newsgroups gmane.comp.web.quixote.cvs
Message-ID <[email protected]>
Author: nascheme
Date: 2004-11-17 19:06:33 -0500 (Wed, 17 Nov 2004)
New Revision: 25634

Modified:
   trunk/quixote/http_response.py
   trunk/quixote/server/simple_server.py
Log:
Stop generating 'Status' header for servers that don't need it.  Add
'include_status' keyword to HTTPResponse.write().


Modified: trunk/quixote/http_response.py
===================================================================
--- trunk/quixote/http_response.py	2004-11-17 19:01:54 UTC (rev 25633)
+++ trunk/quixote/http_response.py	2004-11-18 00:06:33 UTC (rev 25634)
@@ -370,10 +370,6 @@
         """
         headers = []
 
-        # "Status" header must come first.
-        headers.append(("Status", "%03d %s" % (self.status_code,
-                                               self.reason_phrase)))
-
         for name, value in self.headers.items():
             headers.append((name.title(), value))
 
@@ -422,34 +418,21 @@
         else:
             yield self.body # already encoded
 
-    def write(self, output):
-        """write(output : file)
+    def write(self, output, include_status=True):
+        """(output : file, include_status : bool = True)
 
         Write the HTTP response headers and body to 'output'.  This is not
         a complete HTTP response, as it doesn't start with a response
-        status line as specified by RFC 2616.  It does, however, start
-        with a "Status" header as described by the CGI spec.  It
-        is expected that this response is parsed by the web server
-        and turned into a complete HTTP response.
+        status line as specified by RFC 2616.  By default, it does start
+        with a "Status" header as described by the CGI spec.  It is expected
+        that this response is parsed by the web server and turned into a
+        complete HTTP response.
         """
-        # XXX currently we write a response like this:
-        #  Status: 200 OK
-        #  Content-type: text/html; charset=iso-8859-1
-        #  Content-length: 100
-        #  Set-Cookie: foo=bar
-        #  Set-Cookie: bar=baz
-        #
-        #  <html><body>This is a document</body></html>
-        #
-        # which has to be interpreted by the web server to create
-        # a true HTTP response -- that is, this is for a
-        # "parsed header" CGI driver script.
-        #
-        # We should probably have provisions for operating in
-        # "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(output, 'flush')
+        if include_status:
+            # "Status" header must come first.
+            output.write("Status", "%03d %s\r\n" % (self.status_code,
+                                                    self.reason_phrase))
         for name, value in self.generate_headers():
             output.write("%s: %s\r\n" % (name, value))
         output.write("\r\n")

Modified: trunk/quixote/server/simple_server.py
===================================================================
--- trunk/quixote/server/simple_server.py	2004-11-17 19:01:54 UTC (rev 25633)
+++ trunk/quixote/server/simple_server.py	2004-11-18 00:06:33 UTC (rev 25634)
@@ -51,7 +51,7 @@
         try:
             self.send_response(response.get_status_code(),
                                response.get_reason_phrase())
-            response.write(self.wfile)
+            response.write(self.wfile, include_status=False)
         except IOError, err:
             print "IOError while sending response ignored: %s" % err