Coder Social home page Coder Social logo

Support Cors headers about aiohttp-tus HOT 5 CLOSED

okumy avatar okumy commented on July 4, 2024
Support Cors headers

from aiohttp-tus.

Comments (5)

playpauseandstop avatar playpauseandstop commented on July 4, 2024

Hi @Dogfalo,

Yes, there is a known issue with aiohttp-cors, that it doesnโ€™t allow to provide CORS headers for OPTIONS requests cause of the error you mentioned, as it tries to setup a handler for OPTIONS request, but is is already taken

I suggest you to give a try of aiohttp-middlewares and its cors_middleware as it allows to provide CORS headers even for OPTIONS requests

Hope it will work out for you

โ€”โ€”

To make it more obvious, Iโ€™ll update the documentation with tutorial on how to provide CORS headers for aiohttp-tus library

from aiohttp-tus.

Dogfalo avatar Dogfalo commented on July 4, 2024

Thanks for the reply! I am just trying to understand, what makes the aiohttp-middleware different? Does it just add headers into the response of the handler without trying to create a new handler?

from aiohttp-tus.

playpauseandstop avatar playpauseandstop commented on July 4, 2024

The high-level details described in aiohttp-middlewares docs, but if you need more technical details, here they go.

  1. aiohttp-cors registers OPTIONS handler to deal with CORS preflight requests, this resulted in two issues:
    • Inability to use aiohttp-cors with other OPTIONS handlers
    • Inability to use aiohttp-cors with wildcard * handlers, aio-libs/aiohttp-cors#241
  2. While cors_middleware is a regular middleware, which does not register any handlers for dealing with preflight requests. It checks, whether current request is a CORS preflight and if so, does not call handler, but provide an empty response to satisfy CORS needs.

This difference allows cors_middleware to fix both of aiohttp-cors issues as well as simplify dealing with CORS headers for aiohttp.web applications at all, as their setup looks like,

from aiohttp import web
from aiohttp_middlewares import cors_middleware

# Allow CORS requests from URL http://localhost:3000
app = web.Application(
    middlewares=[
        cors_middleware(origins=["http://localhost:3000"])
    ]
)

More examples available in cors_middleware docs.

Hope this makes sense for you.

from aiohttp-tus.

Dogfalo avatar Dogfalo commented on July 4, 2024

Makes sense, thanks for the explanation!

from aiohttp-tus.

playpauseandstop avatar playpauseandstop commented on July 4, 2024

Docs updated: https://aiohttp-tus.readthedocs.io/en/latest/usage.html#cors-headers

from aiohttp-tus.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.