设置了Access-Control-Expose-Headers的JavaScript CORS请求中的无法访问响应标头

时间:2018-06-28 21:27:47

标签: javascript rest amazon-s3 cors

我正在浏览器中使用fetch访问S3对象。存储桶上的CORS设置如下:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <AllowedMethod>HEAD</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
    <AllowedHeader>Authorization</AllowedHeader>
    <AllowedHeader>x-amz-meta-name</AllowedHeader>
    <ExposeHeader>x-amz-meta-name</ExposeHeader>
    <ExposeHeader>x-amz-meta-rank</ExposeHeader>
    <ExposeHeader>x-amz-meta-reason-awarded</ExposeHeader>
    <ExposeHeader>x-amz-meta-date</ExposeHeader>
    <ExposeHeader>x-amz-meta-awarded-for</ExposeHeader>
</CORSRule>
</CORSConfiguration>

在浏览器(chrome)开发人员控制台请求中返回标头:

Accept-Ranges: bytes
Access-Control-Allow-Methods: GET, HEAD
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: x-amz-meta-name, x-amz-meta-rank, x-amz-meta-reason-awarded, x-amz-meta-date, x-amz-meta-awarded-for
Access-Control-Max-Age: 3000
Content-Length: 30527
Content-Type: image/png
Date: Thu, 28 Jun 2018 21:19:05 GMT
ETag: "ba4db22854089fd5d8a6530a40e31747"
Last-Modified: Thu, 28 Jun 2018 20:25:05 GMT
Server: AmazonS3
Vary: Origin, Access-Control-Request-Headers, Access-Control-Request-Method
x-amz-meta-awarded-for: For doing a thing
x-amz-meta-date: 2018-06-26
x-amz-meta-name: Did a thing
x-amz-meta-rank: bronze

但是,当我尝试访问这些标头fetch(url).then(console.log(res.headers))时,它是一个空对象。我想访问元数据标题。我在做什么错了?

0 个答案:

没有答案