@@ -1034,6 +1034,21 @@ async def resolve(self, request: Request) -> UrlMappingMatchInfo:
10341034 resource_index = self ._resource_index
10351035 allowed_methods : Set [str ] = set ()
10361036
1037+ # MatchedSubAppResource is primarily used to match on domain names
1038+ # (though custom rules could match on other things). This means that
1039+ # the traversal algorithm below can't be applied, and that we likely
1040+ # need to check these first so a sub app that defines the same path
1041+ # as a parent app will get priority if there's a domain match.
1042+ #
1043+ # For most cases we do not expect there to be many of these since
1044+ # currently they are only added by `.add_domain()`.
1045+ for resource in self ._matched_sub_app_resources :
1046+ match_dict , allowed = await resource .resolve (request )
1047+ if match_dict is not None :
1048+ return match_dict
1049+ else :
1050+ allowed_methods |= allowed
1051+
10371052 # Walk the url parts looking for candidates. We walk the url backwards
10381053 # to ensure the most explicit match is found first. If there are multiple
10391054 # candidates for a given url part because there are multiple resources
@@ -1051,21 +1066,6 @@ async def resolve(self, request: Request) -> UrlMappingMatchInfo:
10511066 break
10521067 url_part = url_part .rpartition ("/" )[0 ] or "/"
10531068
1054- #
1055- # We didn't find any candidates, so we'll try the matched sub-app
1056- # resources which we have to walk in a linear fashion because they
1057- # have regex/wildcard match rules and we cannot index them.
1058- #
1059- # For most cases we do not expect there to be many of these since
1060- # currently they are only added by `add_domain`
1061- #
1062- for resource in self ._matched_sub_app_resources :
1063- match_dict , allowed = await resource .resolve (request )
1064- if match_dict is not None :
1065- return match_dict
1066- else :
1067- allowed_methods |= allowed
1068-
10691069 if allowed_methods :
10701070 return MatchInfoError (HTTPMethodNotAllowed (request .method , allowed_methods ))
10711071
0 commit comments