direct-io.hg
changeset 10454:0fe87421cc80
Add support to Xend XML-RPC server for HTTP/1.1 Keep-Alive.
This patch fixes a few bugs in the Python SimpleXMLRPC server and enables
HTTP/1.1 by default. This allows a client to use Keep-Alive. Keep-Alive
improves performance by eliminating the overhead of connection setup and,
more importantly, avoids credential caching when executing multiple
commands over a secure connection.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This patch fixes a few bugs in the Python SimpleXMLRPC server and enables
HTTP/1.1 by default. This allows a client to use Keep-Alive. Keep-Alive
improves performance by eliminating the overhead of connection setup and,
more importantly, avoids credential caching when executing multiple
commands over a secure connection.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
author | anthony@rhesis.austin.ibm.com |
---|---|
date | Tue Jun 20 10:25:18 2006 +0100 (2006-06-20) |
parents | 410c81420109 |
children | 95ac3f0f79bc |
files | tools/python/xen/util/xmlrpclib2.py |
line diff
1.1 --- a/tools/python/xen/util/xmlrpclib2.py Mon Jun 19 17:43:04 2006 +0100 1.2 +++ b/tools/python/xen/util/xmlrpclib2.py Tue Jun 20 10:25:18 2006 +0100 1.3 @@ -40,6 +40,31 @@ from xen.xend.XendLogging import log 1.4 # 1.5 # It assumes that the RPC handler is /RPC2. This probably needs to be improved 1.6 1.7 +# We're forced to subclass the RequestHandler class so that we can work around 1.8 +# some bugs in Keep-Alive handling and also enabled it by default 1.9 +class XMLRPCRequestHandler(SimpleXMLRPCRequestHandler): 1.10 + protocol_version = "HTTP/1.1" 1.11 + 1.12 + # this is inspired by SimpleXMLRPCRequestHandler's do_POST but differs 1.13 + # in a few non-trivial ways 1.14 + # 1) we never generate internal server errors. We let the exception 1.15 + # propagate so that it shows up in the Xend debug logs 1.16 + # 2) we don't bother checking for a _dispatch function since we don't 1.17 + # use one 1.18 + # 3) we never shutdown the connection. This appears to be a bug in 1.19 + # SimpleXMLRPCServer.py as it breaks HTTP Keep-Alive 1.20 + def do_POST(self): 1.21 + data = self.rfile.read(int(self.headers["content-length"])) 1.22 + rsp = self.server._marshaled_dispatch(data) 1.23 + 1.24 + self.send_response(200) 1.25 + self.send_header("Content-Type", "text/xml") 1.26 + self.send_header("Content-Length", str(len(rsp))) 1.27 + self.end_headers() 1.28 + 1.29 + self.wfile.write(rsp) 1.30 + self.wfile.flush() 1.31 + 1.32 class HTTPUnixConnection(HTTPConnection): 1.33 def connect(self): 1.34 self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) 1.35 @@ -94,6 +119,10 @@ class ServerProxy(xmlrpclib.ServerProxy) 1.36 class TCPXMLRPCServer(SocketServer.ThreadingMixIn, SimpleXMLRPCServer): 1.37 allow_reuse_address = True 1.38 1.39 + def __init__(self, addr, requestHandler=XMLRPCRequestHandler, 1.40 + logRequests=1): 1.41 + SimpleXMLRPCServer.__init__(self, addr, requestHandler, logRequests) 1.42 + 1.43 def _marshaled_dispatch(self, data, dispatch_method = None): 1.44 params, method = xmlrpclib.loads(data) 1.45 try: 1.46 @@ -131,10 +160,10 @@ class TCPXMLRPCServer(SocketServer.Threa 1.47 # It implements proper support for allow_reuse_address by 1.48 # unlink()'ing an existing socket. 1.49 1.50 -class UnixXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): 1.51 +class UnixXMLRPCRequestHandler(XMLRPCRequestHandler): 1.52 def address_string(self): 1.53 try: 1.54 - return SimpleXMLRPCRequestHandler.address_string(self) 1.55 + return XMLRPCRequestHandler.address_string(self) 1.56 except ValueError, e: 1.57 return self.client_address[:2] 1.58