diff --git a/CHANGES/2585.removal b/CHANGES/2585.removal new file mode 100644 index 00000000000..3055911236a --- /dev/null +++ b/CHANGES/2585.removal @@ -0,0 +1 @@ +Do not create a new resource on `router.add_get(..., allow_head=True)` diff --git a/aiohttp/web_urldispatcher.py b/aiohttp/web_urldispatcher.py index c52b9a5c2b0..ad5d7ecf616 100644 --- a/aiohttp/web_urldispatcher.py +++ b/aiohttp/web_urldispatcher.py @@ -879,14 +879,10 @@ def add_get(self, path, handler, *, name=None, allow_head=True, **kwargs): Shortcut for add_route with method GET, if allow_head is true another route is added allowing head requests to the same endpoint """ + resource = self.add_resource(path, name=name) if allow_head: - # it name is not None append -head to avoid it conflicting with - # the GET route below - head_name = name and '{}-head'.format(name) - self.add_route(hdrs.METH_HEAD, path, handler, - name=head_name, **kwargs) - return self.add_route(hdrs.METH_GET, path, handler, name=name, - **kwargs) + resource.add_route(hdrs.METH_HEAD, handler, **kwargs) + return resource.add_route(hdrs.METH_GET, handler, **kwargs) def add_post(self, path, handler, **kwargs): """