一刀砍死 发表于 2010-07-23 15:57
【补丁】令squid不缓存返回头中包含Set-Cookie的对象
最近有需求要根据后端服务器的返回头来控制是否缓存相关对象。
于是使用了如下配置:[code]acl abcd rep_header Set-Cookie .
cache deny abcd[/code]配置下来却发现acl中rep_header指令其实无法正常工作。
debug的结果显示squid在转发请求到后端以前已经完成了所有的acl检查,所以rep_header无论如何配置其实都是无法生效的。
很多人的squid配置中如下指令其实无法正常工作:[code]acl apache rep_header Server ^Apache
broken_vary_encoding allow apache[/code]随后enic跟踪了一下squid源码,发现squid中相关功能其实并未开发完成,并给出了不缓存返回头中包含Set-Cookie对象的补丁:[code]--- src/http.c 2009-06-26 06:54:13.000000000 +0800
+++ new/http.c 2010-07-23 09:53:06.000000000 +0800
@@ -559,7 +559,16 @@
EBIT_CLR(entry->mem_obj->old_entry->flags, REFRESH_FAILURE);
switch (httpCachableReply(httpState)) {
case 1:
- httpMakePublic(entry);
+ /*=================================================================
+ // funcation: do not cache if response header include "Set-Cookie:"
+ // author: enic
+ // date: 20100722
+ ==================================================================*/
+ if( httpHeaderHas( &reply->header,HDR_SET_COOKIE ) )
+ httpMakePrivate(entry);
+ else
+ httpMakePublic(entry);
break;
case 0:
httpMakePrivate(entry);[/code]
一刀砍死 发表于 2010-07-23 16:04
Changes with nginx 0.8.44 05 Jul 2010
*) Change: now nginx does not cache by default backend responses, if
they have a "Set-Cookie" header line.