AWS CloudFront,`Vary`标题和内容协商 [英] AWS CloudFront, `Vary` header and content negotiation

查看:207
本文介绍了AWS CloudFront,`Vary`标题和内容协商的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试基于客户端接受标头实现内容协商,以便接受 image / webp 的客户端获取webp图像,而客户端没有得到普通的旧jpeg。 webp和jpeg图像由相同的URL提供,即/ images / foo-image /,并且返回的内容因客户端提供的 Accept 标题而异。现在,这在我的网站上运行良好。

I'm trying to implement content negotiation based on client Accept headers so that clients that accept image/webp get webp images while clients that don't get plain old jpeg. webp and jpeg image are served from the same url, i.e. /images/foo-image/ and the content returned varies on the Accept header presented by the client. This now works great on my site.

下一个挑战是让这个有效的AWS CloudFront坐在我的网站前面。我将 Vary 标头设置为 Vary:Accept 让CloudFront知道它必须缓存并提供不同的内容基于客户端接受标题。

Next challenge is to get this working AWS CloudFront sitting in front of my site. I'm setting the Vary header to Vary: Accept to let CloudFront know that it has to cache and serve different content based on the client Accept headers.

不幸的是,这似乎不起作用,即CloudFront只是提供任何服务它首先得到它, Vary 接受尽管如此。有趣的是,CloudFront似乎能够根据 Accept-Encoding (即gzip)改变内容。

This doesn't seem to work unfortunately, i.e. CloudFront just serves up whatever it first gets it's hands on, Vary and Accept notwithstanding. Interestingly, CloudFront does seem to be able to vary content based on Accept-Encoding (i.e. gzip).

有谁知道给出了什么?

推荐答案

事实证明这是记录不应该工作:

It turns out this is documented as not supposed to work:

The only acceptable value for the Vary header is Accept-Encoding. CloudFront ignores other values.

更新: AWS现在支持更复杂的内容协商。我写了一篇关于如何利用这个的博客文章。

UPDATE: AWS now has support for more sophisticated content negotiation. I wrote a blog post on how to take advantage of this.

这篇关于AWS CloudFront,`Vary`标题和内容协商的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆