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

Resolve KeyError exception when calling unsupported request method #298

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
CHANGES
=========

0.8.0 (XXXX-XX-XX)
==================

- Resolve ``KeyError`` exception when requesting with an unsupported
method (#298)

0.7.0 (2018-03-05)
==================

Expand Down
10 changes: 9 additions & 1 deletion aiohttp_cors/cors_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,15 @@ async def _on_response_prepare(self,

# Processing response of non-preflight CORS-enabled request.

config = self._router_adapter.get_non_preflight_request_config(request)
try:
config = self._router_adapter.get_non_preflight_request_config(request)
except KeyError as e:
if response.status == 405 and e.args[0] == "method not supported":
# Permit the response if the method is not supported - e.g: when
# using a class derived from web.View and CorsViewMixin
return

raise

# Handle according to part 6.1 of the CORS specification.

Expand Down
2 changes: 1 addition & 1 deletion aiohttp_cors/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_request_config(cls, request, request_method):
method = getattr(cls, request_method.lower(), None)

if not method:
raise KeyError()
raise KeyError("method not supported")

config_property_key = "{}_cors_config".format(request_method.lower())

Expand Down