From b9a87468bf2845dac988ba3b8a2847f6d56a4bf3 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 29 Apr 2012 16:21:28 -0400 Subject: [PATCH] setups --- README | 0 flask_sslify.py | 21 +++++++++++++++++++++ setup.py | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) delete mode 100644 README create mode 100644 flask_sslify.py create mode 100644 setup.py diff --git a/README b/README deleted file mode 100644 index e69de29..0000000 diff --git a/flask_sslify.py b/flask_sslify.py new file mode 100644 index 0000000..aa881db --- /dev/null +++ b/flask_sslify.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- + +from flask import current_app as app +from flask import request, redirect + +class SSLify(object): + def __init__(self, app): + self.app = app + + self.install_sslify(self.app) + + @classmethod + def install_sslify(cls, app): + + app.before_request(cls.redirect) + + @staticmethod + def redirect(): + if (not request.is_secure) and (not app.debug): + url = request.url.replace('http://', 'https://') + return redirect(url) \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..780acd1 --- /dev/null +++ b/setup.py @@ -0,0 +1,36 @@ +""" +Flask-SSLify +------------ + +This is a simple Flask extension that configures your Flask application to redirect +all incoming requests to ``https``. + +Redirects only occur when ``app.debug`` is ``False``. +""" + +from setuptools import setup + +setup( + name='Flask-SSLify', + version='0.1.0', + url='https://github.com/kennethreitz/flask-sslify', + license='BSD', + author='Kenneth Reitz', + author_email='me@kennethreitz.com', + description='Force SSL on your Flask app.', + long_description=__doc__, + py_modules=['flask_sslify'], + zip_safe=False, + include_package_data=True, + platforms='any', + install_requires=['Flask'], + classifiers=[ + 'Environment :: Web Environment', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: BSD License', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', + 'Topic :: Software Development :: Libraries :: Python Modules' + ] +)