Amazon S3 CORS标头仅在OPTIONS(预检)期间显示,而不在GET请求期间显示

时间:2022-10-29 23:04:15

I have an S3 bucket with the following CORS config.

我有一个带有以下CORS配置的S3存储桶。

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>Authorization</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

The preflight check works as expected.

预检检查按预期工作。

★ ~$ curl -i -X OPTIONS -H "Origin: http://*.com" -H "Access-Control-Request-Method: GET" https://s3.amazonaws.com/random-stuff-ohyea/coderot.gif
HTTP/1.1 200 OK
x-amz-id-2: H6tzMUCJtYgiCRrhj5DucMhjjYtj1kKWqL7u2yaRGEorOeKhu/sTKlgGqY7uHxQC
x-amz-request-id: E784C4373565CBE6
Date: Mon, 21 Oct 2013 22:14:18 GMT
Access-Control-Allow-Origin: http://*.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
Content-Length: 0
Server: AmazonS3

However the origin header on a GET request doesn't.

但是,GET请求中的原始标头却没有。

★ ~$ curl -iI -H "Origin: http://*.com" https://s3.amazonaws.com/random-stuff-ohyea/coderot.gif
HTTP/1.1 200 OK
x-amz-id-2: KlrSviRSwq/40zPwOGp2/lJZk0J2Fyu7kOg966osOvQ2mpbpiv5BLkihGSOfoLd8
x-amz-request-id: 9D051B0001F48AB7
Date: Mon, 21 Oct 2013 22:11:57 GMT
Last-Modified: Mon, 21 Oct 2013 22:10:53 GMT
ETag: "4fa16333380378e116479646b40dd1ee"
Accept-Ranges: bytes
Content-Type: image/gif
Content-Length: 1774246
Server: AmazonS3

This matters because firefox doesn't seem to do preflight checks when loading remote fonts that I have in my s3 bucket. It only seems to send the origin header.

这很重要,因为在加载我在s3存储桶中的远程字体时,firefox似乎没有进行预检检查。它似乎只发送原始标题。

1 个解决方案

#1


4  

With your curl -iI option you will be doing a HEAD request and not a GET request. So you will not get the CORS headers. To simplify testing add <AllowedMethod>HEAD</AllowedMethod> to your CORS configuration and you'll get the expected results.

使用curl -iI选项,您将执行HEAD请求而不是GET请求。所以你不会得到CORS标题。为了简化测试,将 HEAD 添加到CORS配置中,您将获得预期的结果。

#1


4  

With your curl -iI option you will be doing a HEAD request and not a GET request. So you will not get the CORS headers. To simplify testing add <AllowedMethod>HEAD</AllowedMethod> to your CORS configuration and you'll get the expected results.

使用curl -iI选项,您将执行HEAD请求而不是GET请求。所以你不会得到CORS标题。为了简化测试,将 HEAD 添加到CORS配置中,您将获得预期的结果。