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

Resolve KeyError exception when calling unsupported request method #298

wants to merge 1 commit into from

Conversation

attie
Copy link

@attie attie commented Mar 3, 2020

What do these changes do?

When using a web.View class, and querying with an unsupported request method (e.g: class implements GET, client queries with POST), the client would receive an "Empty Reply" from the server, and the server would log a KeyError exception.

This patch resolves the issue, and permits the partially prepared 405 response through to the client.

I'm not sure if this abides by the CORS rules, but it's certainly better than an exception and no response.

Are there changes in behavior for the user?

No changes required.

Related issue number

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes (N/A)
  • Add a new news fragment into the CHANGES folder

Tests

I'm not sure how to go about testing this fix, but I have provided a demo application and curl comamnd to demonstrate it below.

from aiohttp import web
import aiohttp_cors

router = web.RouteTableDef()

@router.view('/ping')
class Ping(web.View, aiohttp_cors.CorsViewMixin):
    async def get(self):
        return web.Response(status=200, text='pong')

app = web.Application()
app.add_routes(router)

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

for route in app.router.routes():
    cors.add(route)

web.run_app(app, port=8080)
curl -D- http://localhost:8080/ping
curl -D- -XPOST http://localhost:8080/ping

When using a web.View class, and querying with an unsupported request
method (e.g: class implements GET, client queries with POST), the client
would receive an "Empty Reply" from the server, and the server would log
a KeyError exception.
@attie
Copy link
Author

attie commented Mar 3, 2020

Please ignore this pull request in favour of #178...

I thought I still had that patch applied, but I didn't.

@attie attie closed this Mar 3, 2020
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

Successfully merging this pull request may close these issues.

1 participant