Git Product home page Git Product logo

Comments (5)

alexbotello avatar alexbotello commented on July 23, 2024 1

Okay, I’ll put a PR in at some point today when I have time.

from starlette.

alexbotello avatar alexbotello commented on July 23, 2024

Sounds good.

Also, on the subject of the Vary: Origin header, it looks like we should be setting that header for specified origins as well.

From https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#The_HTTP_response_headers

If the server specifies a single origin rather than the "*" wildcard, then the server should also include Origin in the Vary response header — to indicate to clients that server responses will differ based on the value of the Origin request header.

from starlette.

tomchristie avatar tomchristie commented on July 23, 2024

Gotcha, yup. Setting the Vary header on standard responses is complicated by the fact that it may already be set, so you need to make so to add-or-include "Origin" in the header value. I guess we should probably start by only considering the no credentialed "wildcard" origins part of this.

from starlette.

alexbotello avatar alexbotello commented on July 23, 2024

Here's the current idea I'm playing with..

async def send(self, message, send=None, request_headers=None):
    ...
    ...
    origin = request_headers.get("origin")
    cookie = request_headers.get("cookie")
    vary = request_headers.get("vary")

    if cookie and self.allow_all_origins:
        headers["Vary"] = f"{vary}, Origin" if vary else "Origin"
        self.simple_headers["Access-Control-Allow-Origin"] = origin
    elif not self.allow_all_origins and self.is_allowed_origin(origin=origin):
        headers["Access-Control-Allow-Origin"] = origin

from starlette.

tomchristie avatar tomchristie commented on July 23, 2024

Cool. Possibly use has_cookie = "cookie" in request_headers just to avoid any Falsey-evaluating edge cases. Also, vary: origin ought to get set in any case except "self.allow_all_origins".

from starlette.

Related Issues (20)

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.