MCPcopy Create free account
hub / github.com/apache/thrift / __init__

Method __init__

lib/py/src/server/THttpServer.py:53–132  ·  view source on GitHub ↗

Set up protocol factories and HTTP (or HTTPS) server. See BaseHTTPServer for server_address. See TServer for protocol factories. To make a secure server, provide the named arguments: * cafile - to validate clients [optional] * cert_file - the server cert

(self,
                 processor,
                 server_address,
                 inputProtocolFactory,
                 outputProtocolFactory=None,
                 server_class=BaseHTTPServer.HTTPServer,
                 **kwargs)

Source from the content-addressed store, hash-verified

51 functions here. This means things like oneway handling are oddly exposed.
52 """
53 def __init__(self,
54 processor,
55 server_address,
56 inputProtocolFactory,
57 outputProtocolFactory=None,
58 server_class=BaseHTTPServer.HTTPServer,
59 **kwargs):
60 """Set up protocol factories and HTTP (or HTTPS) server.
61
62 See BaseHTTPServer for server_address.
63 See TServer for protocol factories.
64
65 To make a secure server, provide the named arguments:
66 * cafile - to validate clients [optional]
67 * cert_file - the server cert
68 * key_file - the server's key
69 """
70 if outputProtocolFactory is None:
71 outputProtocolFactory = inputProtocolFactory
72
73 TServer.TServer.__init__(self, processor, None, None, None,
74 inputProtocolFactory, outputProtocolFactory)
75
76 thttpserver = self
77 self._replied = None
78
79 class RequestHander(BaseHTTPServer.BaseHTTPRequestHandler):
80 def do_POST(self):
81 # Don't care about the request path.
82 thttpserver._replied = False
83 iftrans = TTransport.TFileObjectTransport(self.rfile)
84 itrans = TTransport.TBufferedTransport(
85 iftrans, int(self.headers['Content-Length']))
86 otrans = TTransport.TMemoryBuffer()
87 iprot = thttpserver.inputProtocolFactory.getProtocol(itrans)
88 oprot = thttpserver.outputProtocolFactory.getProtocol(otrans)
89 try:
90 thttpserver.processor.on_message_begin(self.on_begin)
91 thttpserver.processor.process(iprot, oprot)
92 except ResponseException as exn:
93 exn.handler(self)
94 else:
95 if not thttpserver._replied:
96 # If the request was ONEWAY we would have replied already
97 data = otrans.getvalue()
98 self.send_response(200)
99 self.send_header("Content-Length", len(data))
100 self.send_header("Content-Type", "application/x-thrift")
101 self.end_headers()
102 self.wfile.write(data)
103
104 def on_begin(self, name, type, seqid):
105 """
106 Inspect the message header.
107
108 This allows us to post an immediate transport response
109 if the request is a ONEWAY message type.
110 """

Callers

nothing calls this directly

Calls 2

SSLContextMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected