|
regex = /regsuball\(req\.http\.Cookie, \"(.*)\", \"(.*)\"\)/ |
|
|
|
vcl = %Q{ |
|
if (req.http.Cookie) { |
|
set req.http.Cookie = ";" + req.http.Cookie; |
|
set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";"); |
|
set req.http.Cookie = regsuball(req.http.Cookie, ";(user_id|t)=", "; $1="); |
|
set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", ""); |
|
set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", ""); |
|
|
|
if (req.http.Cookie == "") { |
|
remove req.http.Cookie; |
|
} |
|
} |
|
} |
|
|
|
$operations = [] |
|
vcl.gsub(regex) do # surely a better way to do this... how do i .map a regex? |
|
$operations << { regex: $1.strip, replace: $2.strip } |
|
end |
|
|
|
def mangle_cookie(cookie) |
|
puts " ---- " |
|
puts " #{cookie}" |
|
puts " ---- " |
|
cookie = ";"+cookie # this is from the first part of the VCL: 'set req.http.Cookie = ";" + req.http.Cookie;' |
|
$operations.each do |operation| |
|
puts "About to run: #{operation.inspect}" |
|
re = Regexp.new(operation[:regex]) |
|
cookie = cookie.gsub(re) do |
|
(operation[:replace] || '').gsub("$1", $1.to_s) |
|
end |
|
puts "Now the cookie is: #{cookie}\n\n" |
|
end |
|
|
|
if cookie == "" |
|
puts "EMPTY -- publicly cacheable" |
|
else |
|
puts "NOT empty -- cannot cache" |
|
end |
|
end |
|
|
|
mangle_cookie "__utma=21179093278093.141XX4029191.12; __utmz=211798.1412636099.7.2.utmcsr=themarshallproject.org|utmccn=(referral)|utmcmd=referral|utmcct=/; t=IjE0MTQxMTA2MjZ8cHxRRmQyOalQ4aWhOMnh4NUtsRWx6NmhNPSI%3D--bdce16d703d2c3561; user_id=X--29da97db4fac7411; _endrun_session=YWGoxVkcyRXloczNBUEJlNXVLcVNkt1dGc9PQ%3D%3D--59f7500df713b4c471; _ga=GA1.2.193.14565; _gat=1" |
|
mangle_cookie "__utma=2117908093.14140XXXXXX29191.12; __utmz=211798.1412636099.7.2.utmcsr=themarshallproject.org|utmccn=(referral)|utmcmd=referral|utmcct=/; _endrun_session=c2FRdjBra2ZNUinU2VjFOWFl; _ga=GA1.2.1493278093.1408905565; _gat=1" |
The VCL comes from: https://www.varnish-cache.org/trac/wiki/VCLExampleRemovingSomeCookies#RemovingallBUTsomecookies