fix subdomain_matching=False behavior

This commit is contained in:
David Lord 2024-11-10 20:13:05 -08:00
parent 07c7d5730a
commit 4995a775df
No known key found for this signature in database
GPG key ID: 43368A7AA8CC5926
5 changed files with 98 additions and 43 deletions

View file

@ -425,32 +425,40 @@ class Flask(App):
is created at a point where the request context is not yet set
up so the request is passed explicitly.
.. versionadded:: 0.6
.. versionchanged:: 0.9
This can now also be called without a request object when the
URL adapter is created for the application context.
.. versionchanged:: 3.1
If :data:`SERVER_NAME` is set, it does not restrict requests to
only that domain, for both ``subdomain_matching`` and
``host_matching``.
.. versionchanged:: 1.0
:data:`SERVER_NAME` no longer implicitly enables subdomain
matching. Use :attr:`subdomain_matching` instead.
.. versionchanged:: 0.9
This can be called outside a request when the URL adapter is created
for an application context.
.. versionadded:: 0.6
"""
if request is not None:
# If subdomain matching is disabled (the default), use the
# default subdomain in all cases. This should be the default
# in Werkzeug but it currently does not have that feature.
if not self.subdomain_matching:
subdomain = self.url_map.default_subdomain or None
else:
subdomain = None
subdomain = None
server_name = self.config["SERVER_NAME"]
if self.url_map.host_matching:
# Don't pass SERVER_NAME, otherwise it's used and the actual
# host is ignored, which breaks host matching.
server_name = None
elif not self.subdomain_matching:
# Werkzeug doesn't implement subdomain matching yet. Until then,
# disable it by forcing the current subdomain to the default, or
# the empty string.
subdomain = self.url_map.default_subdomain or ""
return self.url_map.bind_to_environ(
request.environ,
server_name=self.config["SERVER_NAME"],
subdomain=subdomain,
request.environ, server_name=server_name, subdomain=subdomain
)
# We need at the very least the server name to be set for this
# to work.
# Need at least SERVER_NAME to match/build outside a request.
if self.config["SERVER_NAME"] is not None:
return self.url_map.bind(
self.config["SERVER_NAME"],