mirror of
https://github.com/python/cpython.git
synced 2025-07-29 22:24:49 +00:00
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]
This commit is contained in:
parent
414f3f90f0
commit
7f686fce40
2 changed files with 106 additions and 9 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue