@@ -1006,6 +1006,21 @@ async def resolve(self, request: Request) -> UrlMappingMatchInfo:
10061006 resource_index = self ._resource_index
10071007 allowed_methods : set [str ] = set ()
10081008
1009+ # MatchedSubAppResource is primarily used to match on domain names
1010+ # (though custom rules could match on other things). This means that
1011+ # the traversal algorithm below can't be applied, and that we likely
1012+ # need to check these first so a sub app that defines the same path
1013+ # as a parent app will get priority if there's a domain match.
1014+ #
1015+ # For most cases we do not expect there to be many of these since
1016+ # currently they are only added by `.add_domain()`.
1017+ for resource in self ._matched_sub_app_resources :
1018+ match_dict , allowed = await resource .resolve (request )
1019+ if match_dict is not None :
1020+ return match_dict
1021+ else :
1022+ allowed_methods |= allowed
1023+
10091024 # Walk the url parts looking for candidates. We walk the url backwards
10101025 # to ensure the most explicit match is found first. If there are multiple
10111026 # candidates for a given url part because there are multiple resources
@@ -1023,21 +1038,6 @@ async def resolve(self, request: Request) -> UrlMappingMatchInfo:
10231038 break
10241039 url_part = url_part .rpartition ("/" )[0 ] or "/"
10251040
1026- #
1027- # We didn't find any candidates, so we'll try the matched sub-app
1028- # resources which we have to walk in a linear fashion because they
1029- # have regex/wildcard match rules and we cannot index them.
1030- #
1031- # For most cases we do not expect there to be many of these since
1032- # currently they are only added by `add_domain`
1033- #
1034- for resource in self ._matched_sub_app_resources :
1035- match_dict , allowed = await resource .resolve (request )
1036- if match_dict is not None :
1037- return match_dict
1038- else :
1039- allowed_methods |= allowed
1040-
10411041 if allowed_methods :
10421042 return MatchInfoError (HTTPMethodNotAllowed (request .method , allowed_methods ))
10431043
0 commit comments