summaryrefslogtreecommitdiffstats
path: root/Lib/http
diff options
context:
space:
mode:
authorSenthil Kumaran <orsenthil@gmail.com>2010-09-30 06:09:18 (GMT)
committerSenthil Kumaran <orsenthil@gmail.com>2010-09-30 06:09:18 (GMT)
commit0f476d49f8d4aa84210392bf13b59afc67b32b31 (patch)
tree3598ceb150a61373b6e0b6233a9f4f68be1ebbcf /Lib/http
parent748cacee469b3e0204b5f1323c22bae7a0f11e1a (diff)
downloadcpython-0f476d49f8d4aa84210392bf13b59afc67b32b31.zip
cpython-0f476d49f8d4aa84210392bf13b59afc67b32b31.tar.gz
cpython-0f476d49f8d4aa84210392bf13b59afc67b32b31.tar.bz2
Issue1491 - BaseHTTPServer incorrectly implements response code 100
Diffstat (limited to 'Lib/http')
-rw-r--r--Lib/http/server.py33
1 files changed, 30 insertions, 3 deletions
diff --git a/Lib/http/server.py b/Lib/http/server.py
index 098ad25..4fa58a2 100644
--- a/Lib/http/server.py
+++ b/Lib/http/server.py
@@ -322,6 +322,30 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
elif (conntype.lower() == 'keep-alive' and
self.protocol_version >= "HTTP/1.1"):
self.close_connection = 0
+ # Examine the headers and look for an Expect directive
+ expect = self.headers.get('Expect', "")
+ if (expect.lower() == "100-continue" and
+ self.protocol_version >= "HTTP/1.1" and
+ self.request_version >= "HTTP/1.1"):
+ if not self.handle_expect_100():
+ return False
+ return True
+
+ def handle_expect_100(self):
+ """Decide what to do with an "Expect: 100-continue" header.
+
+ If the client is expecting a 100 Continue response, we must
+ respond with either a 100 Continue or a final response before
+ waiting for the request body. The default is to always respond
+ with a 100 Continue. You can behave differently (for example,
+ reject unauthorized requests) by overriding this method.
+
+ This method should either return True (possibly after sending
+ a 100 Continue response) or send an error response and return
+ False.
+
+ """
+ self.send_response_only(100)
return True
def handle_one_request(self):
@@ -400,6 +424,12 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
"""
self.log_request(code)
+ self.send_response_only(code, message)
+ self.send_header('Server', self.version_string())
+ self.send_header('Date', self.date_time_string())
+
+ def send_response_only(self, code, message=None):
+ """Send the response header only."""
if message is None:
if code in self.responses:
message = self.responses[code][0]
@@ -408,9 +438,6 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
if self.request_version != 'HTTP/0.9':
self.wfile.write(("%s %d %s\r\n" %
(self.protocol_version, code, message)).encode('ASCII', 'strict'))
- # print (self.protocol_version, code, message)
- self.send_header('Server', self.version_string())
- self.send_header('Date', self.date_time_string())
def send_header(self, keyword, value):
"""Send a MIME header."""