diff options
author | Facundo Batista <facundobatista@gmail.com> | 2007-08-17 19:16:44 +0000 |
---|---|---|
committer | Facundo Batista <facundobatista@gmail.com> | 2007-08-17 19:16:44 +0000 |
commit | 7f686fce40c37a0b8117abb244ec2763cbcd2b58 (patch) | |
tree | b6b94d1973023940f5929b52def6487065d4bc3b /Lib/SimpleXMLRPCServer.py | |
parent | 414f3f90f01f53d8c9bb6e2f626fb8674dcb616d (diff) | |
download | cpython-git-7f686fce40c37a0b8117abb244ec2763cbcd2b58.tar.gz |
Added a flag (_send_traceback_header) to the SimpleXMLRPCServer class
that allows sending back exception/stack trace information about
internal server errors (this flag defaults to False to avoid sending
such information unless explicitly enabled). Added tests to verify
behavior of this new feature (these tests are skipped on win32 because
of problems with WSAEWOULDBLOCK). Renamed HTTPTestCase to
SimpleServerTestCase. [GSoC - Alan McIntyre]
Diffstat (limited to 'Lib/SimpleXMLRPCServer.py')
-rw-r--r-- | Lib/SimpleXMLRPCServer.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/Lib/SimpleXMLRPCServer.py b/Lib/SimpleXMLRPCServer.py index 8c85f80ca9..5fad0af4a3 100644 --- a/Lib/SimpleXMLRPCServer.py +++ b/Lib/SimpleXMLRPCServer.py @@ -105,6 +105,7 @@ import SocketServer import BaseHTTPServer import sys import os +import traceback try: import fcntl except ImportError: @@ -470,9 +471,16 @@ class SimpleXMLRPCRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): response = self.server._marshaled_dispatch( data, getattr(self, '_dispatch', None) ) - except: # This should only happen if the module is buggy + except Exception, e: # This should only happen if the module is buggy # internal error, report as HTTP server error self.send_response(500) + + # Send information about the exception if requested + if hasattr(self.server, '_send_traceback_header') and \ + self.server._send_traceback_header: + self.send_header("X-exception", str(e)) + self.send_header("X-traceback", traceback.format_exc()) + self.end_headers() else: # got a valid XML RPC response @@ -517,6 +525,12 @@ class SimpleXMLRPCServer(SocketServer.TCPServer, allow_reuse_address = True + # Warning: this is for debugging purposes only! Never set this to True in + # production code, as will be sending out sensitive information (exception + # and stack trace details) when exceptions are raised inside + # SimpleXMLRPCRequestHandler.do_POST + _send_traceback_header = False + def __init__(self, addr, requestHandler=SimpleXMLRPCRequestHandler, logRequests=True, allow_none=False, encoding=None, bind_and_activate=True): self.logRequests = logRequests |