[Twisted-web] HTTPS in Twisted
Evandro Dugnani
edugnani at gmail.com
Tue Feb 12 08:32:24 EST 2008
On Feb 8, 2008 9:10 PM, Colin Alston <karnaugh at karnaugh.za.net> wrote:
>
> Change TCPServer to SSLServer. Will also help to read the API docs.
>
Hi Colin,
Thanks for the tip.
Using that, I discovered that I had to generate a private key file,
and then generate a self-signed SSL certificate..
After that, I just created a ssl context with the private key and
the certificate and changed my call "reactor.listenTCP()" to
"reactor.listenSSL()", passing the ssl context as parameter.
Here is the code if anyone wants:
from twisted.web import http
class MyRequestHandler(http.Request):
def process(self):
... my processing code
class MyHttp(http.HTTPChannel):
requestFactory = MyRequestHandler
class MyHttpFactory(http.HTTPFactory):
protocol = MyHttp
if __name__ == "__main__":
from twisted.internet import reactor, ssl
sslContext = ssl.DefaultOpenSSLContextFactory('privkey.pem','cacert.pem')
reactor.listenSSL(TCP_PORT, MyHttpFactory( ), contextFactory = sslContext)
reactor.run( )
Link for reference:
- http://blog.vrplumber.com/356
Regards,
Evandro
More information about the Twisted-web
mailing list