varnish / varnish-modules

Collection of Varnish Cache modules (vmods) by Varnish Software
Other
185 stars 86 forks source link

vmod_header: sometimes, header.remove() does not manage to delete Set-Cookie headers #166

Closed trendymail closed 4 years ago

trendymail commented 4 years ago

Hello!

Please forgive my bad English, I live in France.

Abstract: for each cookie, emitted with Set-Cookie headers, I need to extract its name and append it to a "list".

Warning; maybe I am doing it completely wrong...

In my case, header.remove() does not always succeed to delete "Set-Cookie" headers the first time.

VCL.txt

I have read that vmod_cookie should not be used with "Set-Cookie" headers so it seems that vmod_header is the right one to use.

Any hint would be highly appreciated.

Have a good night!

gquintard commented 4 years ago

Hi,

At this stage, I'm not convinced this is a bug, can you please discuss it on one of the support channels (https://varnish-cache.org/support/) before reopening this ticket please?

One note, you have x-every-cookies and x-all-cookies which could be a source of confusion.

gquintard commented 4 years ago

note that you would probably be better just using std.collect (https://varnish-cache.org/docs/5.1/reference/vmod_std.generated.html#func-collect) then vmod_cookie

trendymail commented 4 years ago

Hello!

Many, many thanks for your quick response and the hint!

Indeed, std.collect() was the solution.

Now, my VCL code is clean and does what I needed: put all cookies' name into one header.

` header.copy ( beresp.http.Set-Cookie, beresp.http.X-Set-Cookie ); std.collect ( beresp.http.X-Set-Cookie, ";" );

set beresp.http.X-Set-Cookie = regsuball ( beresp.http.X-Set-Cookie, "\s+", "" ) + ";"; set beresp.http.X-Set-Cookie = regsuball ( beresp.http.X-Set-Cookie, "([^=;]+)(=[^;]*)?;", ";\1" ); set beresp.http.X-Set-Cookie = regsuball ( beresp.http.X-Set-Cookie, "(?i);(Domain|Expires|HttpOnly|Max-Age|Path|Secure)", "" ); ` Maybe it could help anyone having the same trouble!

Have a good night and thanks again!

gquintard commented 4 years ago

glad I could help. I still think you should use vmod_cookie if you can as it will save you the regex mess, but the important point is it works for you.

Cheers,