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

Revert "Only construct the allowed_methods set once for a StaticResource" #9972

Merged
merged 4 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
3 changes: 3 additions & 0 deletions CHANGES/9972.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Reverted an optimization to avoid rebuilding the allowed methods for `StaticResource` on every request -- by :user:`bdraco`.
bdraco marked this conversation as resolved.
Show resolved Hide resolved

``aiohttp-cors`` needs to be able to modify the allowed methods at run time via this internal.
3 changes: 1 addition & 2 deletions aiohttp/web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,6 @@ 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 @@ -621,10 +620,10 @@ 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)
bdraco marked this conversation as resolved.
Show resolved Hide resolved
if not path.startswith(self._prefix2) and path != self._prefix:
return None, set()

allowed_methods = self._allowed_methods
if method not in allowed_methods:
bdraco marked this conversation as resolved.
Show resolved Hide resolved
return None, allowed_methods

Expand Down
Loading