A simple falcon middleware that configures your app to redirect all incoming requests to HTTPS. This is a port of flask-sslify by Kenneth Reitz from flask to falcon
Install the extension with using pip, or easy_install.
$ pip install -U falcon-sslify
This package exposes a falcon middleware which by default forces SSL on all routes and also enables HSTS
import falcon
from falcon_sslify import FalconSSLify
sslify = FalconSSLify()
api = falcon.API(middleware=[sslify])
flask-sslify also enables HSTS policy for your application by default. By default,
HSTS is set for 1 year ie 31536000 seconds
.
You can change the duration by passing the age
parameter:
sslify = FalconSSlify(age=30000)
By default, HSTS is also enabled for subdomains, you can disable it by
setting the subdomains
parameter to False
sslify = FalconSSlify(subdomains=False)
By default, the redirect is issued with a HTTP 302 response. You can change
that to a HTTP 301 response by setting permanent
parameter to False
sslify = FalconSSlify(permanent=False)
It is also possible to support HTTP and disable redirection on certain endpoints
by passing a list of such paths to skips
parameter.
sslify = FalconSSlify(skips=['http_only', 'anotherpath'])
When using basic auth, this middelware must be placed before any other authentication middleware so that credentials are always propmted on a ssl connection and not on http ones.
.. autoclass:: falcon_sslify.FalconSSLify :members: