aio-libs / aio-libs/aiohttp-cors

method '*' treated differently from others

Aberta
#241 9 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
Python
Estrelas
220
Forks
61
Merge médio
2min
PRs com merge (30d)
3

Descrição

I'm trying to use aiohttp-cors with aiohttp-graphl, which registers a route with the '*' method. I get

`ValueError: already has a '*' handler for all methods`

Here is a small reproducer showing that '*' is different:

```
import asyncio
import aiohttp
import aiohttp_cors
from aiohttp.web_runner import GracefulExit

async def handler(request):
return aiohttp.web.Response(text="Hello!")

app = aiohttp.web.Application()

cors = aiohttp_cors.setup(app)

routes = [{
'method': 'GET',
'path': '/test',
'handler': handler,
'name': 'test-good'
}, {
'method': '*', # ValueError: already has a '*' handler for all methods
'path': '/another-route',
'handler': handler,
'name': 'another-route'
}, ]

for route in routes:
print('creating a route for method', route['method'])
cors.add(
app.router.add_route(
method=route['method'],
path=route['path'],
handler=route['handler'],
name=route['name']
)
)

web.run_app(app, host='localhost', port=8081)
```

which prints

```
creating a route for method GET
creating a route for method *
Traceback (most recent call last):
...
ValueError: already has a '*' handler for all methods
```

Reading the aiohttp-cors code I can see that _is_web_view() is False and then causes this confusing message? But only for method '*' and not GET.

I hacked the aiohttp-cors code to create separate routes for all the methods other than OPTIONS, and my program now runs successfully. But obviously that's not a fix.

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.