lwcolton / falcon-cors

CORS support for Falcon: http://falconframework.org
Apache License 2.0
74 stars 15 forks source link

Requests blocked with 'unallowed method' when route has suffix #20

Open hackedd opened 4 years ago

hackedd commented 4 years ago

When I register a resource with a suffix specified in the add_route call, preflight requests to that resource fail with Aborting response due to unallowed method because _get_resource_methods returns an empty list.

Setting allow_all_methods=True does not help, each request is still checked against the list of methods on the resource.

The example in this gist illustrates the problem. When you run it, it outputs:

Without: ['GET', 'POST']
With suffix: []

Making a CORS POST to /a succeeds, while the same request to /b fails with the unallowed method message.

MonsterDeveloper commented 4 years ago

Facing the same problem.

MonsterDeveloper commented 4 years ago

Found a temporary solution.

Clone falcon_cors from GitHub, and in init.py change _get_resourcemethods function, so `hasattr(resource, 'on' + method.lower())becomesnext((s for s in dir(resource) if method.lower() in s), None)`.

Everything it does is searching for request method substring in resource attributes.