Skip to content
Search

Aiohttp-cors

lastmod 2021-09-18created 2021-03-034 edits

Troubleshooting

CORS malfunction with Variable Resources

When a path like /{plugin}/{tail:.*} is bound to multiple METHODs, CORS does not work. (It is a bug)

The cause of the above problem can be found in aiohttp, in the add_resource method of the UrlDispatcher class in web_urldispatcher.py.

    def add_resource(self, path: str, *, name: Optional[str] = None) -> Resource:
        if path and not path.startswith("/"):
            raise ValueError("path should be started with / or be empty")
        # Reuse last added resource if path and name are the same
        if self._resources:
            resource = self._resources[-1]
            if resource.name == name and resource.raw_match(path):
                return cast(Resource, resource)
        if not ("{" in path or "}" in path or ROUTE_RE.search(path)):
            resource = PlainResource(_requote_path(path), name=name)
            self.register_resource(resource)
            return resource
        resource = DynamicResource(path, name=name)
        self.register_resource(resource)
        return resource

Because it is treated as False in the condition if not ("{" in path or "}" in path or ROUTE_RE.search(path)): on the 9th line above,

!!!!!!!!!!! ... wait... maybe not? Let's check again.

See also

author Zer0 sitemap