From 4f9d0b83d6e522b02a62ecbda8c77056af2c2fd1 Mon Sep 17 00:00:00 2001 From: Semyon Maryasin Date: Sun, 10 Jul 2016 02:33:13 +0300 Subject: [PATCH] Fixed constructor to work without app context In some configurations, extension object is constructed while there is no current application. Without this fix, this extension doesn't support such setups. --- flask_sslify.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/flask_sslify.py b/flask_sslify.py index d0e1c5d..6bf0604 100644 --- a/flask_sslify.py +++ b/flask_sslify.py @@ -12,19 +12,23 @@ class SSLify(object): self.app = app or current_app self.hsts_age = age - self.app.config.setdefault('SSLIFY_SUBDOMAINS', False) - self.app.config.setdefault('SSLIFY_PERMANENT', False) - self.app.config.setdefault('SSLIFY_SKIPS', None) - - self.hsts_include_subdomains = subdomains or self.app.config['SSLIFY_SUBDOMAINS'] - self.permanent = permanent or self.app.config['SSLIFY_PERMANENT'] - self.skip_list = skips or self.app.config['SSLIFY_SKIPS'] + self.hsts_include_subdomains = subdomains + self.permanent = permanent + self.skip_list = skips if app is not None: self.init_app(app) def init_app(self, app): - """Configures the configured Flask app to enforce SSL.""" + """Configures the specified Flask app to enforce SSL.""" + app.config.setdefault('SSLIFY_SUBDOMAINS', False) + app.config.setdefault('SSLIFY_PERMANENT', False) + app.config.setdefault('SSLIFY_SKIPS', None) + + self.hsts_include_subdomains = self.hsts_include_subdomains or app.config['SSLIFY_SUBDOMAINS'] + self.permanent = self.permanent or self.app.config['SSLIFY_PERMANENT'] + self.skip_list = self.skip_list or self.app.config['SSLIFY_SKIPS'] + app.before_request(self.redirect_to_ssl) app.after_request(self.set_hsts_header)