summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-02-23 15:02:28 (GMT)
committerGeorg Brandl <georg@python.org>2008-02-23 15:02:28 (GMT)
commit1647923bbf2a0257eefe5f4bbc44bd11e0d63659 (patch)
tree463f263bd767fe8379844cdc49ea69012f182ee0 /Lib
parent5224d28d38eb784f17c2fed3f48368285df6d17a (diff)
downloadcpython-1647923bbf2a0257eefe5f4bbc44bd11e0d63659.zip
cpython-1647923bbf2a0257eefe5f4bbc44bd11e0d63659.tar.gz
cpython-1647923bbf2a0257eefe5f4bbc44bd11e0d63659.tar.bz2
#1492: allow overriding BaseHTTPServer's content type for error messages.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/BaseHTTPServer.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/Lib/BaseHTTPServer.py b/Lib/BaseHTTPServer.py
index e4e1a14..97d800c 100644
--- a/Lib/BaseHTTPServer.py
+++ b/Lib/BaseHTTPServer.py
@@ -76,7 +76,7 @@ import socket # For gethostbyaddr()
import mimetools
import SocketServer
-# Default error message
+# Default error message template
DEFAULT_ERROR_MESSAGE = """\
<head>
<title>Error response</title>
@@ -89,6 +89,8 @@ DEFAULT_ERROR_MESSAGE = """\
</body>
"""
+DEFAULT_ERROR_CONTENT_TYPE = "text/html"
+
def _quote_html(html):
return html.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
@@ -342,13 +344,14 @@ class BaseHTTPRequestHandler(SocketServer.StreamRequestHandler):
content = (self.error_message_format %
{'code': code, 'message': _quote_html(message), 'explain': explain})
self.send_response(code, message)
- self.send_header("Content-Type", "text/html")
+ self.send_header("Content-Type", self.error_content_type)
self.send_header('Connection', 'close')
self.end_headers()
if self.command != 'HEAD' and code >= 200 and code not in (204, 304):
self.wfile.write(content)
error_message_format = DEFAULT_ERROR_MESSAGE
+ error_content_type = DEFAULT_ERROR_CONTENT_TYPE
def send_response(self, code, message=None):
"""Send the response header and log the response code.