Skip to content

Commit

Permalink
Add support for Werkzeug ProxyFix middleware (#1150)
Browse files Browse the repository at this point in the history
Add an ENABLE_PROXY_FIX config param.  When set to True, insert the Werkzeug ProxyFix
middleware.  This middleware extracts and applies the X-Forwarded-* headers that are
inserted by common proxies and load balancers.  Fixes #1139.
  • Loading branch information
bobziuchkovski authored and mistercrunch committed Sep 20, 2016
1 parent 1ce8acc commit d15a212
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions caravel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from flask_appbuilder.baseviews import expose
from flask_cache import Cache
from flask_migrate import Migrate
from werkzeug.contrib.fixers import ProxyFix


APP_DIR = os.path.dirname(__file__)
Expand Down Expand Up @@ -77,6 +78,9 @@ def checkout(dbapi_con, con_record, con_proxy):
from flask_cors import CORS
CORS(app, **app.config.get('CORS_OPTIONS'))

if app.config.get('ENABLE_PROXY_FIX'):
app.wsgi_app = ProxyFix(app.wsgi_app)


class MyIndexView(IndexView):
@expose('/')
Expand Down
3 changes: 3 additions & 0 deletions caravel/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
# Whether to show the stacktrace on 500 error
SHOW_STACKTRACE = True

# Extract and use X-Forwarded-For/X-Forwarded-Proto headers?
ENABLE_PROXY_FIX = False

# ------------------------------
# GLOBALS FOR APP Builder
# ------------------------------
Expand Down
4 changes: 4 additions & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ load balancer knows if your caravel instance is running. This is provided
at ``/health`` which will return a 200 response containing "OK" if the
webserver is running.

If the load balancer is inserting X-Forwarded-For/X-Forwarded-Proto headers, you
should set `ENABLE_PROXY_FIX = True` in the caravel config file to extract and use
the headers.


Configuration
-------------
Expand Down

0 comments on commit d15a212

Please sign in to comment.