What's the opposite of “Header append Vary User-Agent”, how to remove the “User-Agent” string from “Vary”?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 10:35:25

问题


I know that I can add the User-Agent to the Vary http header with this line in my .htacess:

Header append Vary User-Agent

But how can I remove the User-Agent from the Vary header if it is already set?

According to the mod_headers doc there is an append option, but no equivalent "remove" option.


回答1:


Simple answer below, but you need some shenanigans to avoid sending an empty Vary: header (try to avoid it out of paranoia)

Header edit Vary (.*)User-Agent(.*) $1$2
# Remove leading or trailing ',' without making things complex above
Header edit Vary ^,?(.*),?$ $1
# 2.4-only: remove empty Vary header
Header unset Vary "expr=resp('Vary') =~ /^$/"

x-never-match can be any unlikely-to-ever-be-used header name.




回答2:


Though this is not as generic as being able to remove the specific User-Agent keyword, it gets the job done:

Header set Vary "Accept-Encoding"

This will overwrite your existing header so that the vary header will only have Accept-Encoding



来源:https://stackoverflow.com/questions/27228682/whats-the-opposite-of-header-append-vary-user-agent-how-to-remove-the-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!