Repository navigation
Fix 'Method Not Allowed' on class based views - #178
levkovskyi wants to merge 2 commits into
Conversation
|
Sorry for digging this up, any reason to not merge these changes ? Have been coming across this issue a lot lately ! |
|
Please could we get this merged? I've also run into this issue, and the patch resovles it for me. This is my use-case: router = web.RouteTableDef()
@router.view('/my_endpoint')
class MyEndpoint(web.View, CorsViewMixin):
async def post(self):
print(self.request)
raise web.HTTPOk()When performing a GET against this, the client sees a 500, and the console sees the After applying the patch, the issue is resolved, and the client sees the correct 405. |
|
Is there a plan to merge this? This is completely breaking using views with the library... |
|
|
|
Any chance for merging it? |
|
Somehow, my last comment was 6 years ago, and I've just run into this again - please could we have some feedback / get it merged? 😀 |
|
Monkey patch, if anyone else finds it useful: def __patch_aiohttp_cors():
"""
aiohttp_cors.mixin.CorsViewMixin.get_request_config will raise a KeyError if
the requested method isn't available...
This function will monkey-patch it to return 405 Method Not Allowed instead.
see: https://github.com/aio-libs/aiohttp-cors/pull/178
"""
from aiohttp import web
from aiohttp_cors.urldispatcher_router_adapter import (
ResourcesUrlDispatcherRouterAdapter,
_is_web_view,
)
if getattr(ResourcesUrlDispatcherRouterAdapter, '_patch_vuKPo6w5', False):
return
def vuKPo6w5__request_resource(self, request: web.Request) -> web.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
ResourcesUrlDispatcherRouterAdapter._request_resource = vuKPo6w5__request_resource
ResourcesUrlDispatcherRouterAdapter._patch_vuKPo6w5 = True
__patch_aiohttp_cors() |
|
Was looking at it this week. Going to review in the near future. |
|
Amazing, thanks! |

Fix for #177