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

403 Error when aiohttp resources are not fully merged #226

Open
FabianElsmer opened this issue Feb 22, 2019 · 1 comment
Open

403 Error when aiohttp resources are not fully merged #226

FabianElsmer opened this issue Feb 22, 2019 · 1 comment

Comments

@FabianElsmer
Copy link

FabianElsmer commented Feb 22, 2019

Aiohttp merges resources, when they are added in the correct order:
screenshot from 2019-02-22 15-40-04

When using aiohttp-cors, resources have to be fully merged, or you end up having 2 resources for the same path, one for the GET method one for the POST, but the latter will not be considered when aiohttp-cors answers the OPTIONS request. It seems that aiohttp-cors supports only a single resource per path.

It would be nice if a hint about this could be added to the docs, if the support of multiple resources for the same path is too complex.

Requirements:

aiohttp==3.0.6
aiohttp_cors==0.7.0

Replicate:

def handler():
    pass

app.router.add_route('POST', '/a', handler)
app.router.add_route('GET', '/b', handler)
app.router.add_route('PUT', '/a', handler)

# Configure default CORS settings.
cors = aiohttp_cors.setup(app, defaults={
    "*": aiohttp_cors.ResourceOptions(
    allow_credentials=True,
    expose_headers="*",
    allow_headers="*")
})

# Configure CORS on all routes.
for route in list(app.router.routes()):
    cors.add(route)

@IgorKuzmenko
Copy link

IgorKuzmenko commented Apr 1, 2019

@FabianElsmer we faced with the same issue, allow_methods="*" - could help you.
you could try this:

cors = aiohttp_cors.setup(app, defaults={
"*": aiohttp_cors.ResourceOptions(
            allow_credentials=True,
            expose_headers="*",
            allow_headers="*",
            allow_methods="*"
        )
    })

ianmacartney added a commit to ianmacartney/aiohttp-cors that referenced this issue Aug 15, 2020
Without this, the `OPTIONS` request fails when there are multiple resources per route. This was suggested in aio-libs#226 as a workaround.
@ianmacartney ianmacartney mentioned this issue Aug 15, 2020
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants