Permalink
Browse files

Add optional `permanent` argument, to send 301's instead of 302's.

This fixes #7.
  • Loading branch information...
nvie committed Oct 26, 2012
1 parent 37a07ce commit d7f8d27681c8f95dbafe008ccf351a616f572f48
Showing with 6 additions and 2 deletions.
  1. +6 −2 flask_sslify.py
View
@@ -8,11 +8,12 @@
class SSLify(object):
"""Secures your Flask App."""
- def __init__(self, app, age=YEAR_IN_SECS, subdomains=False):
+ def __init__(self, app, age=YEAR_IN_SECS, subdomains=False, permanent=False):
if app is not None:
self.app = app
self.hsts_age = age
self.hsts_include_subdomains = subdomains
+ self.permanent = permanent
self.init_app(self.app)
else:
@@ -45,7 +46,10 @@ def redirect_to_ssl(self):
if not any(criteria):
if request.url.startswith('http://'):
url = request.url.replace('http://', 'https://', 1)
- r = redirect(url)
+ code = 302
+ if self.permanent:
+ code = 301
+ r = redirect(url, code=code)
return r

0 comments on commit d7f8d27

Please sign in to comment.