From f3933651e11a99961fa710cefcb6ab21ea590443 Mon Sep 17 00:00:00 2001 From: Macoy Madson Date: Wed, 3 Jul 2019 09:51:13 -0700 Subject: [PATCH] Added HTTPS Redirect server --- RedirectToHttpsServer.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 RedirectToHttpsServer.py diff --git a/RedirectToHttpsServer.py b/RedirectToHttpsServer.py new file mode 100755 index 0000000..84d7796 --- /dev/null +++ b/RedirectToHttpsServer.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +import os +import tornado.httpserver +import tornado.web +import tornado.ioloop + +# From https://stackoverflow.com/questions/18353035/redirect-http-requests-to-https-in-tornado +class MainHandler(tornado.web.RequestHandler): + + def prepare(self): + if self.request.protocol == 'http': + self.redirect('https://' + self.request.host, permanent=False) + + def get(self): + self.write("Redirecting to HTTPS") + + +if __name__ == "__main__": + application = tornado.web.Application([ + (r'/', MainHandler) + ]) + application.listen(80) + + tornado.ioloop.IOLoop.current().start()