Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
related:
While the
PREFERRED_URL_SCHEME
options adds some basic support, for actual reverse proxy use cases, theProxyFix
method suggested by @jcox10 is better. But it cannot be used in all circumstances; it must be used only when an actual proxy is in use, and it must be configured with the correct numbers for the headers, so it varies with each use case.Being a Flask app, galactory should be run with a production WSGI server, and how to configure that server is up to each implementer, so I don't want to add too many options for this directly.
But this PR does add a basic way of configuring it. This method cannot be set with CLI/config options; rather it's done through arguments on the
create_configured_app
factory method, for examplecreate_configured_app(proxy_fix=True, x_for=2, x_proto=2, x_port=2)
where all thex_
options are optional and correspond to the options of the same name in theProxyFix
constructor.This can be used with WSGI servers like
gunicorn
, so where before it may have been used like:it can now be used like:
Using
ProxyFix
withx_proto
(which defaults to1
) means not having to setPREFERRED_URL_SCHEME
as long as the proxy sets theX-Forwarded-Proto
header.