Mercurial > cpython-lru_cache-weakref
diff Lib/SimpleXMLRPCServer.py @ 42658:bc31dfcf7dfa legacy-trunk
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]
| author | Facundo Batista <facundobatista@gmail.com> |
|---|---|
| date | Fri, 17 Aug 2007 19:16:44 +0000 |
| parents | 101a1ab573db |
| children | a375b1346eb3 |
line wrap: on
line diff
--- a/Lib/SimpleXMLRPCServer.py Fri Aug 17 18:59:58 2007 +0000 +++ b/Lib/SimpleXMLRPCServer.py Fri Aug 17 19:16:44 2007 +0000 @@ -105,6 +105,7 @@ import BaseHTTPServer import sys import os +import traceback try: import fcntl except ImportError: @@ -470,9 +471,16 @@ 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 @@ 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
