From 9c12df10c408e2a644a7b729cf36f7dda26ccccf Mon Sep 17 00:00:00 2001 From: Jeffrey Gelens Date: Thu, 18 Jul 2013 09:43:09 +0200 Subject: [PATCH 1/3] Fixed bug when initializing SSLify without 'app' argument and using init_app(app) to set it later. --- flask_sslify.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/flask_sslify.py b/flask_sslify.py index e747889..8559bc4 100644 --- a/flask_sslify.py +++ b/flask_sslify.py @@ -8,7 +8,7 @@ YEAR_IN_SECS = 31536000 class SSLify(object): """Secures your Flask App.""" - def __init__(self, app, age=YEAR_IN_SECS, subdomains=False, permanent=False): + def __init__(self, app=None, age=YEAR_IN_SECS, subdomains=False, permanent=False): if app is not None: self.app = app self.hsts_age = age @@ -21,6 +21,8 @@ class SSLify(object): def init_app(self, app): """Configures the configured Flask app to enforce SSL.""" + + self.app = app app.before_request(self.redirect_to_ssl) app.after_request(self.set_hsts_header) From d2a0f8330f6fe6bd69f787344757e9e7724528fa Mon Sep 17 00:00:00 2001 From: Jeffrey Gelens Date: Thu, 18 Jul 2013 09:45:33 +0200 Subject: [PATCH 2/3] self.app in __init__ is not needed anymore --- flask_sslify.py | 1 - 1 file changed, 1 deletion(-) diff --git a/flask_sslify.py b/flask_sslify.py index 8559bc4..6ab2e8b 100644 --- a/flask_sslify.py +++ b/flask_sslify.py @@ -10,7 +10,6 @@ class SSLify(object): def __init__(self, app=None, 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 From f7c3aa9b923e883a792de6c0a02d3af86fa8fba2 Mon Sep 17 00:00:00 2001 From: Jeffrey Gelens Date: Thu, 18 Jul 2013 09:48:41 +0200 Subject: [PATCH 3/3] Move hsts_age and other variables set in __init__ out of the if statement --- flask_sslify.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/flask_sslify.py b/flask_sslify.py index 6ab2e8b..7b602aa 100644 --- a/flask_sslify.py +++ b/flask_sslify.py @@ -9,14 +9,12 @@ class SSLify(object): """Secures your Flask App.""" def __init__(self, app=None, age=YEAR_IN_SECS, subdomains=False, permanent=False): - if app is not None: - self.hsts_age = age - self.hsts_include_subdomains = subdomains - self.permanent = permanent + self.hsts_age = age + self.hsts_include_subdomains = subdomains + self.permanent = permanent + if app is not None: self.init_app(self.app) - else: - self.app = None def init_app(self, app): """Configures the configured Flask app to enforce SSL."""