Help--
You received this message because you are subscribed to the Google Groups "Tornado Web Server" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-tornad...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
You can override prepare to redirect to https like below:
class MainHandler(tornado.web.RequestHandler):
def prepare(self):
if self.request.protocol == "http":
self.redirect("https://%s" % self.request.full_url()[len("http://"):],
permanent=True)
def get(self):
self.write("Hello, world")
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import tornado.ioloop
import tornado.web
import tornado.httpserver
import http.server
class MainHandler(tornado.web.RequestHandler):
def prepare(self):
if self.request.protocol == "http":
self.redirect("https://%s" % self.request.full_url()[len("http://"):], permanent=True)
def get(self):
self.write("Hello, world")
application = tornado.web.Application([
(r'/', MainHandler),
])
http_server = tornado.httpserver.HTTPServer(application,
ssl_options = {
"certfile": os.path.join("/var/pyTest/keys/", "cert.pem"),
"keyfile": os.path.join("/var/pyTest/keys/", "key.pem"),
}
)
if __name__ == '__main__':
http_server.listen(4443)
tornado.ioloop.IOLoop.instance().start()