Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only construct the allowed_methods set once for a StaticResource #9911

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions aiohttp/web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ def __init__(
"HEAD", self._handle, self, expect_handler=expect_handler
),
}
self._allowed_methods = set(self._routes)

def url_for( # type: ignore[override]
self,
Expand Down Expand Up @@ -620,15 +621,18 @@ def set_options_route(self, handler: Handler) -> None:
async def resolve(self, request: Request) -> _Resolve:
path = request.rel_url.path_safe
method = request.method
allowed_methods = set(self._routes)
if not path.startswith(self._prefix2) and path != self._prefix:
return None, set()

allowed_methods = self._allowed_methods
if method not in allowed_methods:
return None, allowed_methods

match_dict = {"filename": _unquote_path_safe(path[len(self._prefix) + 1 :])}
return (UrlMappingMatchInfo(match_dict, self._routes[method]), allowed_methods)
return (
UrlMappingMatchInfo(match_dict, self._routes[method]),
self._allowed_methods,
)
bdraco marked this conversation as resolved.
Show resolved Hide resolved

def __len__(self) -> int:
return len(self._routes)
Expand Down
Loading