diff --git a/aiohttp/web_urldispatcher.py b/aiohttp/web_urldispatcher.py index ee8dff7ed78..68bd888f764 100644 --- a/aiohttp/web_urldispatcher.py +++ b/aiohttp/web_urldispatcher.py @@ -655,7 +655,8 @@ def __await__(self): return (yield from self.__iter__()) def _raise_allowed_methods(self): - allowed_methods = {m for m in hdrs.METH_ALL if hasattr(self, m)} + allowed_methods = { + m for m in hdrs.METH_ALL if hasattr(self, m.lower())} raise HTTPMethodNotAllowed(self.request.method, allowed_methods) diff --git a/tests/test_classbasedview.py b/tests/test_classbasedview.py index a0613e16819..2dbce5a357b 100644 --- a/tests/test_classbasedview.py +++ b/tests/test_classbasedview.py @@ -34,11 +34,13 @@ class MyView(View): @asyncio.coroutine def get(self): return web.Response(text='OK') + options = get request = mock.Mock() request.method = 'UNKNOWN' with pytest.raises(web.HTTPMethodNotAllowed) as ctx: yield from MyView(request) + assert ctx.value.headers['allow'] == 'GET,OPTIONS' assert ctx.value.status == 405 @@ -49,9 +51,11 @@ class MyView(View): @asyncio.coroutine def get(self): return web.Response(text='OK') + options = delete = get request = mock.Mock() request.method = 'POST' with pytest.raises(web.HTTPMethodNotAllowed) as ctx: yield from MyView(request) + assert ctx.value.headers['allow'] == 'DELETE,GET,OPTIONS' assert ctx.value.status == 405