def __init__(self, *args, **kwargs): self.loop = kwargs.pop('loop') TServer.__init__(self, *args, **kwargs) self.closed = False self.server = None
def __init__(self, processor, server_address, itrans_factory, iprot_factory, server_class=http_server.HTTPServer): """Set up protocol factories and HTTP server. See http.server for server_address. See TServer for protocol factories. """ TServer.__init__(self, processor, trans=None, itrans_factory=itrans_factory, iprot_factory=iprot_factory, otrans_factory=None, oprot_factory=None) thttpserver = self class RequestHander(http_server.BaseHTTPRequestHandler): # Don't care about the request path. def do_POST(self): # Don't care about the request path. # Pre-read all of the data into a BytesIO. Buffered transport # was previously configured to read everything on the first # consumption, but that was a hack relying on the internal # mechanism and prevents other transports from working, so # replicate that properly to prevent timeout issues content_len = int(self.headers['Content-Length']) buf = BytesIO(self.rfile.read(content_len)) itrans = TFileObjectTransport(buf) itrans = thttpserver.itrans_factory.get_transport(itrans) iprot = thttpserver.iprot_factory.get_protocol(itrans) otrans = TMemoryBuffer() oprot = thttpserver.oprot_factory.get_protocol(otrans) try: thttpserver.processor.process(iprot, oprot) except ResponseException as exn: exn.handler(self) else: self.send_response(200) self.send_header("content-type", "application/x-thrift") self.end_headers() self.wfile.write(otrans.getvalue()) self.httpd = server_class(server_address, RequestHander)
def __init__(self, processor, server_address, iprot_factory, server_class=http_server.HTTPServer): """Set up protocol factories and HTTP server. See http.server for server_address. See TServer for protocol factories. """ TServer.__init__(self, processor, trans=None, itrans_factory=None, iprot_factory=iprot_factory, otrans_factory=None, oprot_factory=None) thttpserver = self class RequestHander(http_server.BaseHTTPRequestHandler): # Don't care about the request path. def do_POST(self): # Don't care about the request path. itrans = TFileObjectTransport(self.rfile) otrans = TFileObjectTransport(self.wfile) itrans = TBufferedTransport( itrans, int(self.headers['Content-Length'])) otrans = TMemoryBuffer() iprot = thttpserver.iprot_factory.get_protocol(itrans) oprot = thttpserver.oprot_factory.get_protocol(otrans) try: thttpserver.processor.process(iprot, oprot) except ResponseException as exn: exn.handler(self) else: self.send_response(200) self.send_header("content-type", "application/x-thrift") self.end_headers() self.wfile.write(otrans.getvalue()) self.httpd = server_class(server_address, RequestHander)
def __init__(self, processor, server_address, itrans_factory, iprot_factory, server_class=http_server.HTTPServer): TServer.__init__(self, processor, trans=None, itrans_factory=itrans_factory, iprot_factory=iprot_factory, otrans_factory=None, oprot_factory=None) thttpserver = self class RequestHander(http_server.BaseHTTPRequestHandler): def do_POST(self): content_len = int(self.headers['Content-Length']) buf = BytesIO(self.rfile.read(content_len)) itrans = TFileObjectTransport(buf) itrans = thttpserver.itrans_factory.get_transport(itrans) iprot = thttpserver.iprot_factory.get_protocol(itrans) otrans = TMemoryBuffer() oprot = thttpserver.oprot_factory.get_protocol(otrans) try: thttpserver.processor.process(iprot, oprot) except ResponseException as exn: exn.handler(self) else: self.send_response(200) self.send_header("content-type", "application/x-thrift") self.end_headers() self.wfile.write(otrans.getvalue()) self.httpd = server_class(server_address, RequestHander)