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
meetmangukiya and webknjaz committed Mar 26, 2020
1 parent 50753ea commit fa52a26
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 @@ -184,6 +184,7 @@ Mathieu Dugré
Matt VanEseltine
Matthieu Hauglustaine
Matthieu Rigal
Meet Mangukiya
Michael Ihnatenko
Mikhail Burshteyn
Mikhail Kashkin
Expand Down
3 changes: 3 additions & 0 deletions aiohttp/web_routedef.py
Expand Up @@ -191,6 +191,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 fa52a26

Please sign in to comment.