summaryrefslogtreecommitdiffstats
path: root/Lib/http
diff options
context:
space:
mode:
authorSenthil Kumaran <orsenthil@gmail.com>2010-11-21 14:36:14 (GMT)
committerSenthil Kumaran <orsenthil@gmail.com>2010-11-21 14:36:14 (GMT)
commite4dad4f8e239be6d9d1fd3e5398584a7d2a14edb (patch)
treeff6526bd9de4fe65ec484ca7f5e0fd029b858897 /Lib/http
parenta73dc9d5e8ba2320a5aebf8c24ab665ccdfed5f8 (diff)
downloadcpython-e4dad4f8e239be6d9d1fd3e5398584a7d2a14edb.zip
cpython-e4dad4f8e239be6d9d1fd3e5398584a7d2a14edb.tar.gz
cpython-e4dad4f8e239be6d9d1fd3e5398584a7d2a14edb.tar.bz2
Fix issue3709 - BaseHTTPRequestHandler will buffer the headers and write only on end_headers call.
Diffstat (limited to 'Lib/http')
-rw-r--r--Lib/http/server.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/Lib/http/server.py b/Lib/http/server.py
index 8a6ba70..5ebfd25 100644
--- a/Lib/http/server.py
+++ b/Lib/http/server.py
@@ -443,7 +443,10 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
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 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
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.