Index: Doc/library/basehttpserver.rst =================================================================== --- Doc/library/basehttpserver.rst (revision 60975) +++ Doc/library/basehttpserver.rst (working copy) @@ -122,6 +122,11 @@ class variable. +.. attribute:: BaseHTTPRequestHandler.error_content_type + + Specifies the Content-Type HTTP header of error responses sent to the client. + The default value is ``'text/html'``. + .. attribute:: BaseHTTPRequestHandler.protocol_version This specifies the HTTP protocol version used in responses. If set to Index: Lib/BaseHTTPServer.py =================================================================== --- Lib/BaseHTTPServer.py (revision 60975) +++ Lib/BaseHTTPServer.py (working copy) @@ -76,7 +76,7 @@ import mimetools import SocketServer -# Default error message +# Default error message template DEFAULT_ERROR_MESSAGE = """\ Error response @@ -89,6 +89,8 @@ """ +DEFAULT_ERROR_CONTENT_TYPE = "text/html" + def _quote_html(html): return html.replace("&", "&").replace("<", "<").replace(">", ">") @@ -342,13 +344,14 @@ 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.