summaryrefslogtreecommitdiffstats
path: root/Lib/http
diff options
context:
space:
mode:
authorSenthil Kumaran <senthil@uthcode.com>2013-03-15 14:53:21 (GMT)
committerSenthil Kumaran <senthil@uthcode.com>2013-03-15 14:53:21 (GMT)
commit2688644eef0766ddb22695664e76fe567ceabac5 (patch)
treecb7abef878a28fc916b68476de5c7ffed19efbaf /Lib/http
parent12bb353d43e69f4ec1bd9959261aedddbe760f7d (diff)
downloadcpython-2688644eef0766ddb22695664e76fe567ceabac5.zip
cpython-2688644eef0766ddb22695664e76fe567ceabac5.tar.gz
cpython-2688644eef0766ddb22695664e76fe567ceabac5.tar.bz2
#1291 http.server's send_error takes an optional explain argument
Diffstat (limited to 'Lib/http')
-rw-r--r--Lib/http/server.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/Lib/http/server.py b/Lib/http/server.py
index 1873b13..e47e034 100644
--- a/Lib/http/server.py
+++ b/Lib/http/server.py
@@ -401,12 +401,17 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
while not self.close_connection:
self.handle_one_request()
- def send_error(self, code, message=None):
+ def send_error(self, code, message=None, explain=None):
"""Send and log an error reply.
- Arguments are the error code, and a detailed message.
- The detailed message defaults to the short entry matching the
- response code.
+ Arguments are
+ * code: an HTTP error code
+ 3 digits
+ * message: a simple optional 1 line reason phrase.
+ *( HTAB / SP / VCHAR / %x80-FF )
+ defaults to short entry matching the response code
+ * explain: a detailed message defaults to the long entry
+ matching the response code.
This sends an error response (so it must be called before any
output has been generated), logs the error, and finally sends
@@ -420,11 +425,12 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
shortmsg, longmsg = '???', '???'
if message is None:
message = shortmsg
- explain = longmsg
+ if explain is None:
+ explain = longmsg
self.log_error("code %d, message %s", code, message)
# using _quote_html to prevent Cross Site Scripting attacks (see bug #1100201)
content = (self.error_message_format %
- {'code': code, 'message': _quote_html(message), 'explain': explain})
+ {'code': code, 'message': _quote_html(message), 'explain': _quote_html(explain)})
body = content.encode('UTF-8', 'replace')
self.send_response(code, message)
self.send_header("Content-Type", self.error_content_type)