Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add middleware to set wsgi.url_scheme based on X-Scheme.

  • Loading branch information...
commit 0f6a2e86583b7b475e9d49c478ba9b8cf86fd799 1 parent 44fb287
@spladug spladug authored
Showing with 14 additions and 0 deletions.
  1. +14 −0 postcards/__init__.py
View
14 postcards/__init__.py
@@ -10,5 +10,19 @@
app.config.from_envvar('POSTCARD_SETTINGS')
app.secret_key = os.urandom(24)
+# let us handle ssl better
+# http://flask.pocoo.org/snippets/35/
+class ReverseProxied(object):
+ def __init__(self, app):
+ self.app = app
+
+ def __call__(self, environ, start_response):
+ scheme = environ.get("HTTP_X_SCHEME")
+ if scheme:
+ environ["wsgi.url_scheme"] = scheme
+ return self.app(environ, start_response)
+
+app.wsgi_app = ReverseProxied(app.wsgi_app)
+
# make sure the views get registered
import postcards.views
Please sign in to comment.
Something went wrong with that request. Please try again.