大网数据广告活动
服务器运维问答

nginx gzip Vary header together with existing Vary headers

· 52CE 我爱测

I'm trying to active gzip compression and I have set the option gzip_vary on; to include the Vary: Accept-Encoding header. The problem is, my application is already seting a Vary: header. So the response is now having two Vary: h…

问题原文

原帖链接 · Dennis C. · CC BY-SA 3.0

I'm trying to active gzip compression and I have set the option gzip_vary on; to include the Vary: Accept-Encoding header.

The problem is, my application is already seting a Vary: header. So the response is now having two Vary: headers, one from my application and one from nginx.

HTTP/1.1 200 OK
Server: nginx
Date: Sat, 17 Dec 2016 13:28:38 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Vary: Accept-Encoding
Last-Modified: Sat, 17 Dec 2016 13:28:38 GMT
Cache-Control: no-cache, no-store, must-revalidate, max-age=0
Pragma: no-cache
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Vary: User-Agent
Content-Encoding: gzip

But I guess instead it should be rather like this:

Vary: Accept-Encoding, User Agent

How can I achieve this?

已采纳解答

原帖链接 · Jason Martin · CC BY-SA 3.0

RFC2616 states duplicate headers are acceptable and should be treated the same as a single header with a comma-separated list of values:

Multiple message-header fields with the same field-name MAY be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)]. It MUST be possible to combine the multiple header fields into one "field-name: field-value" pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma. The order in which header fields with the same field-name are received is therefore significant to the interpretation of the combined field value, and thus a proxy MUST NOT change the order of these field values when a message is forwarded.

So, you don't need to do anything to get the proper behavior.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-12-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。