Skip to content

Commit

Permalink
Optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Oct 30, 2021
1 parent bc6476a commit 519539b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions aiohttp/web_urldispatcher.py
Expand Up @@ -495,6 +495,7 @@ def __init__(self, prefix: str, *, name: Optional[str] = None) -> None:
assert prefix in ("", "/") or not prefix.endswith("/"), prefix
super().__init__(name=name)
self._prefix = _requote_path(prefix)
self._prefix2 = self._prefix + "/"

@property
def canonical(self) -> str:
Expand All @@ -505,6 +506,7 @@ def add_prefix(self, prefix: str) -> None:
assert not prefix.endswith("/")
assert len(prefix) > 1
self._prefix = prefix + self._prefix
self._prefix2 = self._prefix + "/"

def raw_match(self, prefix: str) -> bool:
return False
Expand Down Expand Up @@ -616,7 +618,7 @@ async def resolve(self, request: Request) -> _Resolve:
path = request.rel_url.raw_path
method = request.method
allowed_methods = set(self._routes)
if not path.startswith(self._prefix + "/") and path != self._prefix:
if not path.startswith(self._prefix2) and path != self._prefix:
return None, set()

if method not in allowed_methods:
Expand Down Expand Up @@ -732,7 +734,7 @@ def get_info(self) -> _InfoDict:

async def resolve(self, request: Request) -> _Resolve:
if (
not request.url.raw_path.startswith(self._prefix + "/")
not request.url.raw_path.startswith(self._prefix2)
and request.url.raw_path != self._prefix
):
return None, set()
Expand Down

0 comments on commit 519539b

Please sign in to comment.