From 60314dac74af6bb1b385051184cde2e72f24eddd Mon Sep 17 00:00:00 2001 From: Belousow Makc Date: Thu, 16 Jun 2016 20:04:59 +0300 Subject: [PATCH] Fix empty ALLOW Response header for cls based View We must check existing lower http method names for assembing ALLOW header and passing into web.HTTPMethodNotAllowed. --- aiohttp/web_urldispatcher.py | 3 ++- tests/test_classbasedview.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/aiohttp/web_urldispatcher.py b/aiohttp/web_urldispatcher.py index 58d5a17c2a3..9acddd56ab3 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