Warning when using HTTP instead of HTTPS

I have a pure CherryPy server that has been running for several years now. I recently decided to add SSL support. In this case, it was sufficient to provide the certificate and key files and assign the correct values ​​to the variables cherrypy.server.ssl_certificate

and cherrypy.server.ssl_private_key

.

I would like to alert you to this change whenever someone tries to access the page using "http: // ..." instead of "https: // ...". Is there an easy way to achieve this without many changes to my system? Another option would be to redirect the HTTP access to the HTTPS file, which can be done easily?

+3


source to share


1 answer


I would create a custom handler to achieve what you need. This is automatically redirected to HTTPS.



class Functions():
    def check_ssl(self=None):
        # check if url is in https and redirect if http
        if cherrypy.request.scheme == "http":
            cherrypy.HTTPRedirect(Referer.replace("http:", "https:"))

    cherrypy.tools.Functions = cherrypy.Tool('before_handler', check_ssl)

      

+3


source







All Articles