Skip to content

Aiohttp-cors

Troubleshooting

Variable Resources 의 CORS 오동작

/{plugin}/{tail:.*}라는 경로를 여러 개의 METHOD 로 연결했을 경우 CORS 가 작동하지 않는다. (버그이다)

위 문제의 원인을 aiohttp에서 web_urldispatcher.pyUrlDispatcher 클래스, add_resource 메서드에서 확인 가능하다.

    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

위에서 9번째 라인의 if not ("{" in path or "}" in path or ROUTE_RE.search(path)): 조건에서 False 처리되기 때문에,

!!!!!!!!!!! ... 잠만... 아닌듯? 다시 확인해보자.

See also