Skip to content

Commit

Permalink
Merge pull request #35 from alphagov/bug-94292928-email-links-not-gen…
Browse files Browse the repository at this point in the history
…erated-with-https

[#94292928] Allow HTTP proto to be configured
  • Loading branch information
allait committed May 15, 2015
2 parents 81ffc7a + 2754154 commit a17ce81
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
18 changes: 18 additions & 0 deletions dmutils/proxy_fix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from werkzeug.contrib.fixers import ProxyFix


class CustomProxyFix(object):
def __init__(self, app, forwarded_proto):
self.app = ProxyFix(app)
self.forwarded_proto = forwarded_proto

def __call__(self, environ, start_response):
environ.update({
"HTTP_X_FORWARDED_PROTO": self.forwarded_proto
})
return self.app(environ, start_response)


def init_app(app):
app.wsgi_app = CustomProxyFix(app.wsgi_app,
app.config.get('DM_HTTP_PROTO', 'http'))
17 changes: 17 additions & 0 deletions tests/test_proxy_fix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from flask import request

from dmutils import proxy_fix


def test_proxy_fix(app):
app.config['DM_HTTP_PROTO'] = 'foo'
proxy_fix.init_app(app)

@app.route("/")
def foo():
return request.environ['HTTP_X_FORWARDED_PROTO']

with app.app_context():
client = app.test_client()
response = client.get('/')
assert response.data.decode('utf-8') == 'foo'

0 comments on commit a17ce81

Please sign in to comment.