gpt4 book ai didi

CORS 预检响应包括变化 :Origin and Access-Control-Max-Age?

转载 作者:行者123 更新时间:2023-12-04 17:23:04 27 4
gpt4 key购买 nike

我想知道浏览器如何处理包括 在内的 CORS 预检响应变化:起源 Access-Control-Max-Age 标题。

本声明来自 https://www.w3.org/TR/cors/

Resources that wish to enable themselves to be shared with multiple Origins but do not respond uniformly with "*" must in practice generate the Access-Control-Allow-Origin header dynamically in response to every request they wish to allow. As a consequence, authors of such resources should send a Vary: Origin HTTP header or provide other appropriate control directives to prevent caching of such responses, which may be inaccurate if re-used across-origins



从这句话我明白 变化:起源 将告诉浏览器阻止预检响应的缓存(如果 allow-origin: * not used)

Access-Control-Max-Age 会告诉浏览器将缓存预检响应一段时间。

问题:
  • 如果预检响应中存在两个 header ,它是否有效?
  • 如果响应包含这两个 header ,浏览器如何处理预检响应?

  • 谢谢!

    最佳答案

    根据规范要求 Vary: Origin不会影响 CORS-preflight cache 的行为.

    Is it valid if both of the headers exist in a preflight response?


    是的,这是有效的。但是如果 Vary header 存在,它对 CORS 预检缓存没有影响。

    How browsers handle Preflight response if the response includes both that headers


    对于 CORS 预检缓存,浏览器完全忽略 Vary header 并且只使用 Access-Control-Max-Age 的值标题。

    my understand is Vary: Origin will tell browsers won't cache preflight result


    这不是 Fetch 规范中的要求。
    CORS-preflight cache不是 HTTP 规范中的要求所涵盖的通用 HTTP 缓存。这是一个特殊的缓存,其行为由 Fetch 规范专门定义。并且 Fetch 规范没有说明任何关于 CORS 预检缓存的行为受 Vary 影响的要求,甚至是间接要求。响应头。
    而是 the Fetch spec says just this :

    Let max-age be the result of extracting header list values given Access-Control-Max-Age and response’s header list.


    这并没有说明检查 Vary设置 max-age 之前的 header 值。
    并且因为规范没有明确说明是否/如何使用 Vary在决定是否填充 CORS 预检缓存时,浏览器不得使用 Vary做的时候。
    如果浏览器确实使用了 Vary在处理 CORS 预检缓存时,该浏览器将不符合 CORS 预检缓存的规范要求。

    关于CORS 预检响应包括变化 :Origin and Access-Control-Max-Age?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42848208/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com