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

Fix 'Method Not Allowed' on class based views #178

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion aiohttp_cors/urldispatcher_router_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,12 @@ def _request_route(self, request: web.Request) -> web.ResourceRoute:
return match_info.route

def _request_resource(self, request: web.Request) -> web.Resource:
return self._request_route(request).resource
route = self._request_route(request)
if _is_web_view(route, strict=False) and not hasattr(route.handler, request.method.lower()):
resource = None
else:
resource = route.resource
return resource

def is_preflight_request(self, request: web.Request) -> bool:
"""Is `request` is a CORS preflight request."""
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,15 @@ async def test_preflight_default_disallowed_method(aiohttp_client, make_app):
assert header_name not in resp.headers


async def test_method_not_allowed(aiohttp_client, make_app):
app = make_app(None, {"http://client1.example.org": ResourceOptions()})

client = await aiohttp_client(app)

resp = await client.post("/resource")
assert resp.status == 405


async def test_preflight_req_multiple_routes_with_one_options(aiohttp_client):
"""Test CORS preflight handling on resource that is available through
several routes.
Expand Down