Beispiel #1
0
 def channel_protocol_factory():
     return _GenericHTTPChannelProtocol(_LessNoisyHTTPChannel())
Beispiel #2
0
    def _ProtocolFactory(self):

        return _GenericHTTPChannelProtocol(FatHTTPChannel())
Beispiel #3
0
class Counter(resource.Resource):
    isLeaf = True
    numberRequests = 0

    def render_GET(self, request):
        print(request.transport.TLS)
        self.numberRequests += 1
        addr = request.getClientAddress()
        print("[{}:{}] GET {}".format(addr.host, addr.port,
                                      request.uri.decode()))
        request.setHeader(b"content-type", b"text/plain")
        content = u"I am request #{} in {} channel\n".format(
            self.numberRequests,
            "Secure" if request.transport.TLS else "Plain")
        return content.encode("ascii")


pem_priv = open(KEY, "rb").read()
pem_cert = open(CERT, "rb").read()
priv = ssl.KeyPair.load(pem_priv, format=crypto.FILETYPE_PEM)
cert = ssl.PrivateCertificate.load(pem_cert, priv, format=crypto.FILETYPE_PEM)

s = server.Site(Counter())
s.protocol = lambda: http._GenericHTTPChannelProtocol(myHTTPChannel())
s.options = cert.options()

reactor.listenTCP(PORT, s, interface=HOST)

print("Server started at {}:{}".format(HOST, PORT))
reactor.run()