-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from alphagov/bug-94292928-email-links-not-gen…
…erated-with-https [#94292928] Allow HTTP proto to be configured
- Loading branch information
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |