Note how /healthcheck now behaves differently on the two subdomains. On "static", we now get back the on_static endpoint, and on "foo" we still get back the on_healthcheck endpoint.
I see the same behavior with the latest version of werkzeug (3.0.3 at time of writing).
Summary
Is this change in behavior intentional? The PR https://github.com/pallets/werkzeug/pull/2433 just describes this as a faster matcher, it doesn't say anything about a change in behavior.
Is there some way of configuring a route across all subdomains that takes precedence over the subdomain specific /<path:filename> rule in my example?
Workaround
I don't have a great workaround for this. I can get close to the pre-werkzeug 2.2 behavior by adding a 3rd rule specifically for the "static" subdomain:
(Sorry for the convoluted title: I don't know the right vocabulary for this.)
I noticed when upgrading to Werkzeug 2.2+, two of my routing rules have swapped priority.
Sample application
Here's a simple werkzeug application. The important part is the 2 rules:
cat server.py
```python from werkzeug.wrappers import Request, Response from werkzeug.routing import Map, Rule from werkzeug.exceptions import HTTPException class SimpleServer: def __init__(self, server_name: str, url_map: Map): self._server_name = server_name self._url_map = url_map def dispatch_request(self, request): adapter = self._url_map.bind_to_environ(request.environ, server_name=self._server_name) try: endpoint, values = adapter.match() return endpoint(request, **values) except HTTPException as e: return e def wsgi_app(self, environ, start_response): request = Request(environ) response = self.dispatch_request(request) return response(environ, start_response) def __call__(self, environ, start_response): return self.wsgi_app(environ, start_response) class Demo(SimpleServer): def __init__(self, server_name: str): url_map = Map([ Rule('/Before (on werkzeug <2.2)
Run the server:
Note how /healthcheck behaves the same on both the "static" subdomain, and a different subdomain "foo":
"static" subdomain:
"foo" subdomain:
After (werkzeug 2.2+)
Note how /healthcheck now behaves differently on the two subdomains. On "static", we now get back the
on_static
endpoint, and on "foo" we still get back theon_healthcheck
endpoint."static" subdomain:
"foo" subdomain:
I see the same behavior with the latest version of werkzeug (3.0.3 at time of writing).
Summary
Is this change in behavior intentional? The PR https://github.com/pallets/werkzeug/pull/2433 just describes this as a faster matcher, it doesn't say anything about a change in behavior.
Is there some way of configuring a route across all subdomains that takes precedence over the subdomain specific
/<path:filename>
rule in my example?Workaround
I don't have a great workaround for this. I can get close to the pre-werkzeug 2.2 behavior by adding a 3rd rule specifically for the "static" subdomain:
But this behaves a bit differently: there's no
subdomain
argument passed to my endpoint handler. Environment:@pgjones, since you wrote the new matcher