【问题标题】:How to correctly set Expires headers on Google Cloud Storage?如何在 Google Cloud Storage 上正确设置 Expires 标头?
【发布时间】:2012-10-12 23:39:15
【问题描述】:

Google Cloud Storage Developer Guide 解释了如何设置 Cache-Control 标头,并解释了它们对 api 一致性行为的关键影响,但没有提及 Expires 标头,它们似乎也没有从 Cache-Control 配置继承.

无论 Cache-Control 设置如何,Expires 标头似乎总是等于请求时间加上 1 年,例如。

$ gsutil setmeta -h "Cache-Control:300" gs://example-bucket/doc.html 

通过

向 Google Cloud Storage 存储桶 (example-bucket) 中的文档 (doc.html) 发出了请求
$ curl -I http://example-bucket.storage.googleapis.com/doc.html

产生了以下标题

HTTP/1.1 200 OK
Server: HTTP Upload Server Built on Oct 3 2012 16:52:30 (1349308350)
Date: Sat, 13 Oct 2012 00:51:13 GMT
Cache-Control: 300, no-transform
Expires: Sun, 13 Oct 2013 00:51:13 GMT
Last-Modified: Fri, 12 Oct 2012 20:08:41 GMT
ETag: "28fafe4213ae34c7d3ebf9ac5a6aade8"
x-goog-sequence-number: 82
x-goog-generation: 1347601001449082
x-goog-metageneration: 1
Content-Type: text/html
Accept-Ranges: bytes
Content-Length: 7069
Vary: Origin

【问题讨论】:

标签: google-cloud-storage


【解决方案1】:

不知道您为什么说 Expires 标头显示请求时间加上 1 年。在您的示例中,Expires 标头显示请求日期后一小时的时间戳,这是意料之中的。

我刚刚做了一个实验,我通过以下命令将对象的最大年龄设置为 3600,然后设置为 7200:

gsutil setmeta "Cache-Control:max-age=7200" gs://marc-us/xyz.txt

然后我使用带有 -D 选项的 gsutil cat 命令检索对象以查看请求/响应详细信息,如下所示:

gsutil -D cat gs://marc-us/xyz.txt

在两个实验中,Expires 标头根据对象的 max-age 设置(即请求时间后一小时和请求时间后两小时)生成预期时间戳。

【讨论】:

  • 感谢您的快速响应。我会用 gsutil 工具试试这个。我一直在使用fog
  • 使用 v2.0 api 绝对可以正常工作。我是using the v1.0 api。可能是交互库引入了错误...
  • “过期:2013 年 10 月 13 日星期日”如何不比“日期:2012 年 10 月 13 日星期六”晚一年?
【解决方案2】:

看起来这是由格式错误的标头引起的。呵呵。

Cache-Control: 300, no-transform

应该是

Cache-Control: public, max-age=300, no-transform

如果设置正确,它们就会起作用。见RFC 2616 (HTTP/1.1) Section 14.9 (Cache-Control)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-18
    • 2019-11-02
    • 2023-03-30
    • 2021-09-15
    • 2012-08-20
    • 1970-01-01
    • 2016-09-13
    相关资源
    最近更新 更多