THRIFT-597. py: Python THttpServer performance improvements

This enables buffered I/O and ThreadingMixin.

Patch: David Reiss

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@991971 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/py/src/server/THttpServer.py b/lib/py/src/server/THttpServer.py
index 21fc314..9bf80cb 100644
--- a/lib/py/src/server/THttpServer.py
+++ b/lib/py/src/server/THttpServer.py
@@ -29,7 +29,8 @@
   acting as a mock version of an Apache-based PHP Thrift endpoint."""
 
   def __init__(self, processor, server_address,
-      inputProtocolFactory, outputProtocolFactory = None):
+      inputProtocolFactory, outputProtocolFactory = None,
+      server_class = BaseHTTPServer.HTTPServer):
     """Set up protocol factories and HTTP server.
 
     See BaseHTTPServer for server_address.
@@ -52,12 +53,14 @@
 
         itrans = TTransport.TFileObjectTransport(self.rfile)
         otrans = TTransport.TFileObjectTransport(self.wfile)
+        itrans = TTransport.TBufferedTransport(itrans, int(self.headers['Content-Length']))
+        otrans = TTransport.TBufferedTransport(otrans)
         iprot = thttpserver.inputProtocolFactory.getProtocol(itrans)
         oprot = thttpserver.outputProtocolFactory.getProtocol(otrans)
         thttpserver.processor.process(iprot, oprot)
         otrans.flush()
 
-    self.httpd = BaseHTTPServer.HTTPServer(server_address, RequestHander)
+    self.httpd = server_class(server_address, RequestHander)
 
   def serve(self):
     self.httpd.serve_forever()