Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add minimal ProxyFix support #48

Merged
merged 3 commits into from
Dec 26, 2022
Merged

add minimal ProxyFix support #48

merged 3 commits into from
Dec 26, 2022

Conversation

briantist
Copy link
Owner

related:

While the PREFERRED_URL_SCHEME options adds some basic support, for actual reverse proxy use cases, the ProxyFix 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 example create_configured_app(proxy_fix=True, x_for=2, x_proto=2, x_port=2) where all the x_ options are optional and correspond to the options of the same name in the ProxyFix constructor.

This can be used with WSGI servers like gunicorn, so where before it may have been used like:

gunicorn 'galactory:create_configured_app'

it can now be used like:

gunicorn 'galactory:create_configured_app(proxy_fix=True, x_for=2)'

Using ProxyFix with x_proto (which defaults to 1) means not having to set PREFERRED_URL_SCHEME as long as the proxy sets the X-Forwarded-Proto header.

@briantist briantist added the enhancement New feature or request label Dec 26, 2022
@briantist briantist self-assigned this Dec 26, 2022
@codecov
Copy link

codecov bot commented Dec 26, 2022

Codecov Report

Base: 56.83% // Head: 56.70% // Decreases project coverage by -0.13% ⚠️

Coverage data is based on head (95fd474) compared to base (fbb8e67).
Patch coverage: 40.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #48      +/-   ##
==========================================
- Coverage   56.83%   56.70%   -0.14%     
==========================================
  Files          26       26              
  Lines         943      947       +4     
==========================================
+ Hits          536      537       +1     
- Misses        407      410       +3     
Impacted Files Coverage Δ
galactory/__init__.py 40.27% <40.00%> (-0.90%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@briantist briantist merged commit 0aa4915 into main Dec 26, 2022
@briantist briantist deleted the factory-proxyfix branch December 26, 2022 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant