#110 Add CORS headers to 404s too.
Merged 2 years ago by pingou. Opened 2 years ago by qulogic.
qulogic/mdapi cors404  into  master

file modified
+8 -1
@@ -22,13 +22,20 @@ 

          get_pkg_changelog

  )

  

+ 

  @middleware

  async def add_cors_headers(request, handler):

-     resp = await handler(request)

+     try:

+         resp = await handler(request)

+     except web.HTTPException as e:

+         e.headers['Access-Control-Allow-Origin'] = '*'

+         e.headers['Access-Control-Allow-Methods'] = 'GET'

+         raise

      resp.headers['Access-Control-Allow-Origin'] = '*'

      resp.headers['Access-Control-Allow-Methods'] = 'GET'

      return resp

  

+ 

  async def init_app():

      """ Creates the aiohttp application.

          This function creates a web application configure the routes and

Though maybe you'll want to add it to any error result.

Maybe fixes #89, perhaps.

Also not sure if you would also like the Content-Type to be switched to application/json as originally reported in #89.

I'm wondering if restricting to 404 only makes sense, what do you think?

It may not be necessary, that was just the minimal change.

rebased onto 6234462

2 years ago

I changed it to always add headers, but it may be good to also always return JSON, see #111.

+1 to always return JSON but it should be complementary to the http code I think.

For this PR, I'm +1 with the code change itself, but I think the commit message needs to be adjusted :)

rebased onto d752db6

2 years ago

rebased onto a246e35

2 years ago

rebased onto 90d32f0

2 years ago

Pull-Request has been merged by pingou

2 years ago
Metadata