Changes between Version 1 and Version 2 of VCLExampleRemovingSomeCookies


Ignore:
Timestamp:
2009-12-10 12:03:57 (4 years ago)
Author:
zviratko
Comment:

better version for removing cookies, and a nasty hack for removing all but some cookies

Legend:

Unmodified
Added
Removed
Modified
  • VCLExampleRemovingSomeCookies

    v1 v2  
    1919 
    2020Replace foo with the name of the cookie you wish to remove. 
     21 
     22= Another version for removing some cookies = 
     23 
     24{{{ 
     25sub vcl_recv { 
     26if (req.http.Cookie) { 
     27    set req.http.Cookie = regsuball(req.http.Cookie, "(^|; ) *__utm.=[^;]+;? *", "\1"); # removes all cookies named __utm? (utma, utmb...) - tracking thing 
     28 
     29    if (req.http.Cookie == "") { 
     30        remove req.http.Cookie; 
     31    } 
     32} 
     33}}} 
     34 
     35= Removing all BUT some cookies = 
     36(warning - not pretty) 
     37 
     38removes all cookies but the ones named COOKIE1 and COOKIE2 
     39 
     40{{{ 
     41sub vcl_recv { 
     42if (req.http.Cookie) { 
     43    set req.http.Cookie = regsuball(req.http.Cookie, "(^|;) +", "\1"); 
     44    set req.http.Cookie = regsuball(req.http.Cookie, "(^|;)(COOKIE1|COOKIE2)=", "; \2="); 
     45    set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", ""); 
     46    set req.http.Cookie = regsub(req.http.Cookie, "^[; ]*|[; ]*$", ""); 
     47 
     48    if (req.http.Cookie == "") { 
     49        remove req.http.Cookie; 
     50    } 
     51} 
     52}}}