diff Lib/http/server.py @ 66351:9717153d558d

Fix issue3709 - BaseHTTPRequestHandler will buffer the headers and write only on end_headers call.
author Senthil Kumaran <orsenthil@gmail.com>
date Sun, 21 Nov 2010 14:36:14 +0000
parents b0249d0839ed
children 8b02f7f9475b
line wrap: on
line diff
--- a/Lib/http/server.py	Sun Nov 21 13:56:42 2010 +0000
+++ b/Lib/http/server.py	Sun Nov 21 14:36:14 2010 +0000
@@ -443,7 +443,10 @@
     def send_header(self, keyword, value):
         """Send a MIME header."""
         if self.request_version != 'HTTP/0.9':
-            self.wfile.write(("%s: %s\r\n" % (keyword, value)).encode('ASCII', 'strict'))
+            if not hasattr(self, '_headers_buffer'):
+                self._headers_buffer = []
+            self._headers_buffer.append(
+                ("%s: %s\r\n" % (keyword, value)).encode('ASCII', 'strict'))
 
         if keyword.lower() == 'connection':
             if value.lower() == 'close':
@@ -454,7 +457,9 @@
     def end_headers(self):
         """Send the blank line ending the MIME headers."""
         if self.request_version != 'HTTP/0.9':
-            self.wfile.write(b"\r\n")
+            self._headers_buffer.append(b"\r\n")
+            self.wfile.write(b"".join(self._headers_buffer))
+            self._headers_buffer = []
 
     def log_request(self, code='-', size='-'):
         """Log an accepted request.