gpt4 book ai didi

google-chrome - Chrome + CORS +缓存-从两个不同的来源请求相同的文件

转载 作者:行者123 更新时间:2023-12-04 01:14:22 45 4
gpt4 key购买 nike

我遇到了我似乎无法完全理解的Chrome问题,我很好奇这里的人以前是否曾处理过该问题。在Firefox中不会重现。步骤如下:

  • 启动隐身浏览器,导航到https://foo.mysite.com,然后让页面上的JS向S3发出https://s3.amazonaws.com/mystuff/file.json的GET ajax请求。您会收到200的答复:
    HTTP/1.1 200 OK
    x-amz-id-2: somestuffhere
    x-amz-request-id: somestuffhere
    Date: Tue, 14 Oct 2014 03:06:41 GMT
    Access-Control-Allow-Origin: https://foo.mysite.com
    Access-Control-Allow-Methods: GET
    Access-Control-Max-Age: 3000
    Access-Control-Allow-Credentials: true
    Vary: Origin, Access-Control-Request-Headers, Access-Control-Request-Method
    Cache-Control: max-age=86400
    Content-Encoding: gzip
    Last-Modified: Sun, 05 Oct 2014 00:29:53 GMT
    ETag: "fe76607baa40a793eb3b3cbd373a3fb8"
    Accept-Ranges: bytes
    Content-Type: application/json
    Content-Length: 5609
    Server: AmazonS3
  • 打开第二个选项卡,导航到https://bar.mysite.com并让其JS向S3发出GET ajax请求,以获取同一文件https://s3.amazonaws.com/mystuff/file.json。取得以下304回应:
    HTTP/1.1 304 Not Modified
    x-amz-id-2: somestuffhere
    x-amz-request-id: somestuffhere
    Date: Tue, 14 Oct 2014 03:06:58 GMT
    Access-Control-Allow-Origin: https://bar.mysite.com
    Access-Control-Allow-Methods: GET
    Access-Control-Max-Age: 3000
    Access-Control-Allow-Credentials: true
    Vary: Origin, Access-Control-Request-Headers, Access-Control-Request-Method
    Cache-Control: max-age=86400
    Last-Modified: Sun, 05 Oct 2014 00:29:53 GMT
    ETag: "fe76607baa40a793eb3b3cbd373a3fb8"
    Server: AmazonS3
  • 打开第三个选项卡,导航至https://foo.mysite.com(第一个站点),然后重复与1中相同的步骤。Chrome由于CORS原因终止响应并报告以下内容:
    XMLHttpRequest cannot load https://s3.amazonaws.com/mystuff/file.json. The 'Access-Control-Allow-Origin' header has a value 'https://bar.mysite.com' that is not equal to the supplied origin. Origin 'https://foo.mysite.com' is therefore not allowed access.

  • 这是什么故事?在Firefox中不会重现。在Firefox中,我很高兴在第2步和第3步中都得到了304,我也希望在Chrome中也能看到。

    Chrome中此问题的临时解决方法是在S3中的文件上设置 Cache-Control:no-cache ,但随后我强制我们的客户端无缘无故地重新下载该文件,因此这不是真正的解决方案。

    这是预期的行为并已记录在案吗?这是Chrome的错误吗?还有其他想法吗?

    最佳答案

    看起来这是由Chromium issue 260239引起的

    关于google-chrome - Chrome + CORS +缓存-从两个不同的来源请求相同的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26352083/

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