Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support registering OPTIONS HTTP method handlers via RouteTableDef #4615

Merged
merged 2 commits into from Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -181,6 +181,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