gpt4 book ai didi

google-cloud-storage - 为 Cloud Storage 使用不同的内容编码

转载 作者:行者123 更新时间:2023-12-05 07:24:25 28 4
gpt4 key购买 nike

我希望能够支持对使用 Google Cloud Storage 托管的静态 Assets 进行 Brotli 和 Gzip 编码。为此,我想在将文件上传为 <filename> 之前对其进行编码, <filename>.gz<filename>.br .问题是,我找不到使用 Accept-Encoding 重定向请求的方法到正确的文件。

我研究过使用:

  • 以某种方式重定向传入请求的 Cloud Functions(类似于 AWS Cloudfront Lambda),但它似乎不受支持
  • 负载均衡器将请求重定向到不同的存储桶,但据我所知,它只能根据主机名/路径重定向到不同的存储桶
  • Cloud CDN,但它似乎没有任何对此有帮助的功能

请求/响应示例

假设桶example-bucket包含以下文件:

library.js
library.js.gz
library.js.br
示例 1
GET http://storage.googleapis.com/example-bucket/library.js

Accept-Encoding: gzip, deflate, br
Content-Encoding: br

<Contents of http://storage.googleapis.com/example-bucket/library.js.br>
示例 2
GET http://storage.googleapis.com/example-bucket/library.js

Accept-Encoding: gzip, deflate
Content-Encoding: gzip

<Contents of http://storage.googleapis.com/example-bucket/library.js.gz>

有没有一种方法可以简单、高效且经济高效地实现上述目标?我意识到可以通过 App Engine 托管我自己的服务器,并让它负责将请求路由到存储桶,但这是唯一的方法吗?

最佳答案

Lambda@edge 是一种方法,但简单的方法是将 CloudFront 上的 Accept-encoding header 列入白名单,以便 CloudFront 可以将其传递给 Origin,您可以在 Origin 上配置以根据 Accept-encoding 提供文件标题。

如果您打算使用 Lambda@edge,我建议您使用 Origin 请求功能。1. 将 Accept-encoding header 列入白名单2.Origin请求函数读取header值,改变请求URI路径。

关于google-cloud-storage - 为 Cloud Storage 使用不同的内容编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55425081/

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