@@ -977,6 +977,21 @@ async def resolve(self, request: Request) -> UrlMappingMatchInfo:
977977 resource_index = self ._resource_index
978978 allowed_methods : set [str ] = set ()
979979
980+ # MatchedSubAppResource is primarily used to match on domain names
981+ # (though custom rules could match on other things). This means that
982+ # the traversal algorithm below can't be applied, and that we likely
983+ # need to check these first so a sub app that defines the same path
984+ # as a parent app will get priority if there's a domain match.
985+ #
986+ # For most cases we do not expect there to be many of these since
987+ # currently they are only added by `.add_domain()`.
988+ for resource in self ._matched_sub_app_resources :
989+ match_dict , allowed = await resource .resolve (request )
990+ if match_dict is not None :
991+ return match_dict
992+ else :
993+ allowed_methods |= allowed
994+
980995 # Walk the url parts looking for candidates. We walk the url backwards
981996 # to ensure the most explicit match is found first. If there are multiple
982997 # candidates for a given url part because there are multiple resources
@@ -994,21 +1009,6 @@ async def resolve(self, request: Request) -> UrlMappingMatchInfo:
9941009 break
9951010 url_part = url_part .rpartition ("/" )[0 ] or "/"
9961011
997- #
998- # We didn't find any candidates, so we'll try the matched sub-app
999- # resources which we have to walk in a linear fashion because they
1000- # have regex/wildcard match rules and we cannot index them.
1001- #
1002- # For most cases we do not expect there to be many of these since
1003- # currently they are only added by `add_domain`
1004- #
1005- for resource in self ._matched_sub_app_resources :
1006- match_dict , allowed = await resource .resolve (request )
1007- if match_dict is not None :
1008- return match_dict
1009- else :
1010- allowed_methods |= allowed
1011-
10121012 if allowed_methods :
10131013 return MatchInfoError (HTTPMethodNotAllowed (request .method , allowed_methods ))
10141014
0 commit comments