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 support for Flask.host_matching #274

Merged
merged 2 commits into from
Jul 15, 2024

Conversation

samuelhwilliams
Copy link
Contributor

@samuelhwilliams samuelhwilliams commented Jul 2, 2024

Allows configuration of Flask-DebugToolbar to support a Flask app running in host_matching mode.

When Flask is configured this way, routes are each tied to a host definition. This can either be a single explicit host, or a host definition that includes variable values similar to Werkzeug path definitions, eg <subdomain>.toolbar.com.

Handling explicit domains is simple, as the host can be passed through directly - and this happens automatically.

If the host contains any variable parts, then calls to url_for need to be able to access the appropriate values for those variables. If the host string specified by the user contains arbitrary variables, it's difficult for the toolbar to know what those should evaluate to. So we restrict the possible options for the toolbar host to one of two options here: either a single explicit host, or a full-wildcard host. The wildcard host is managed internally by Flask-DebugToolbar so that we know: 1) the variable name, and 2) what value to inject for it (the current request's host).

Fix: #269

Allows configuration of Flask-DebugToolbar to support a Flask app
running in `host_matching` mode.

When Flask is configured this way, routes are each tied to a `host`
definition. This can either be a single explicit host, or a host
definition that includes variable values similar to Werkzeug path
definitions, eg `<subdomain>.toolbar.com`.

Handling explicit domains is simple, as the host can be passed through
directly - and this happens automatically.

If the host contains any variable parts, then calls to `url_for` need to
be able to access the appropriate values for those variables. If the
host string specified by the user contains arbitrary variables, it's
difficult for the toolbar to know what those should evaluate to. So we
restrict the possible options for the toolbar host to one of two options
here: either a single explicit host, or a full-wildcard host. The
wildcard host is managed internally by Flask-DebugToolbar so that we
know: 1) the variable name, and 2) what value to inject for it (the
current request's host).
Copy link
Contributor

@macnewbold macnewbold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Samuel shared a pre-PR version of this change on the Issue #269 and answered a bunch of my questions and adjusted things already from any feedback I have. As far as I can tell, it's good to go, but I'd love more eyes on it.

@samuelhwilliams
Copy link
Contributor Author

Are we good to merge this in? What needs to happen to schedule a release with this change? :)

Please let me know if you're waiting on anything from my end.

@macnewbold macnewbold enabled auto-merge July 15, 2024 20:24
@macnewbold macnewbold merged commit 877e69d into pallets-eco:main Jul 15, 2024
9 checks passed
@samuelhwilliams samuelhwilliams deleted the add-host-support-v2 branch July 15, 2024 20:46
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Support for host_matching
3 participants