Skip to content

Commit

Permalink
Support registering OPTIONS HTTP method handlers via RouteTableDef
Browse files Browse the repository at this point in the history
PR #4615 by @meetmangukiya

Fixes #4663

Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
  • Loading branch information
2 people authored and asvetlov committed Nov 19, 2021
1 parent c693b74 commit 4521ba3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/4663.bugfix
@@ -0,0 +1 @@
Support registering OPTIONS HTTP method handlers via RouteTableDef.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Expand Up @@ -210,6 +210,7 @@ Mathias Fröjdman
Mathieu Dugré
Matthieu Hauglustaine
Matthieu Rigal
Meet Mangukiya
Michael Ihnatenko
Michał Górny
Mikhail Burshteyn
Expand Down
3 changes: 3 additions & 0 deletions aiohttp/web_routedef.py
Expand Up @@ -206,6 +206,9 @@ def patch(self, path: str, **kwargs: Any) -> _Deco:
def delete(self, path: str, **kwargs: Any) -> _Deco:
return self.route(hdrs.METH_DELETE, path, **kwargs)

def options(self, path: str, **kwargs: Any) -> _Deco:
return self.route(hdrs.METH_OPTIONS, path, **kwargs)

def view(self, path: str, **kwargs: Any) -> _Deco:
return self.route(hdrs.METH_ANY, path, **kwargs)

Expand Down
16 changes: 16 additions & 0 deletions tests/test_route_def.py
Expand Up @@ -232,6 +232,22 @@ async def handler(request):
assert str(route.url_for()) == "/path"


def test_options_deco(router) -> None:
routes = web.RouteTableDef()

@routes.options('/path')
async def handler(request):
pass

router.add_routes(routes)

assert len(router.routes()) == 1

route = list(router.routes())[0]
assert route.method == 'OPTIONS'
assert str(route.url_for()) == '/path'


def test_route_deco(router) -> None:
routes = web.RouteTableDef()

Expand Down

0 comments on commit 4521ba3

Please sign in to comment.