Hi, Why unset req.http.cookie; ?
Wouldn’t this require applications to read $_SERVER[‘HTTP_COOKIE1’] and $_SERVER[‘HTTP_COOKIE2’]. as opposed to $_COOKIE. (I can see this might break PHP sessions working out of the box). Or I misunderstood? Best Regards, Danila > On 30 May 2017, at 10:38, Guillaume Quintard <[email protected]> > wrote: > > Hi, > > As you said, the hashing is only based on the URL (and host/ip), that means > that Varnish can cache "/account.html" with cookie "user=alice" and deliver > it to the request "/account.html" with cookie "user=bob", is that an issue? > > I highly recommend using vmod cookie to avoid the regex madness. I'd also > extract the cookies into their own headers and hash them inconditionally, > giving something like: > > sub vcl_recv { > cookie.parse(req.http.cookie); > set req.http.cookie1 = cookie.get("COOKIE1"); > set req.http.cookie2 = cookie.get("COOKIE2"); > unset req.http.cookie; > } > > sub vcl_hash { > hash_data(req.http.cookie1); > hash_data(req.http.cookie2); > } > > -- > Guillaume Quintard > > On Tue, May 30, 2017 at 6:40 AM, sreeranj s <[email protected] > <mailto:[email protected]>> wrote: > Let me reiterate the question. > > By default varnish will not cache if there is cookie present in request or a > set-cookie value is there in server response. In the following case we have > retained COOKIE1 and |COOKIE2, but can varnish still caches the responses(I > have the unset cookie from backend responses), by returning hash in vcl > recv. No changes in vcl_hash is made, so caching is based on req_url. > > Please advise on any issues on this approach. > > *************************************** > sub vcl_recv { > 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, > ";(COOKIE1|COOKIE2)=", "; \1="); > set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", ""); > set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", ""); > > if (req.http.Cookie == "") { > unset req.http.Cookie; > return(pass) > } > return(hash) > } > } > *************************************** > > > > On Mon, May 29, 2017 at 9:45 PM, sreeranj s <[email protected] > <mailto:[email protected]>> wrote: > Hi, > > As per the link > https://varnish-cache.org/docs/4.0/users-guide/increasing-your-hitrate.html > <https://varnish-cache.org/docs/4.0/users-guide/increasing-your-hitrate.html>, > following code will help us to retain COOKIE1 and |COOKIE2, but strip other > cookies. So COOKIE1 and |COOKIE2 is send to backend. I have the following > questions. > > 1) By default varnish will not cache if there is cookie present in request or > a set-cookie value is there in server response. In the following case we have > retained COOKIE1 and |COOKIE2, but I still have varnish caches the > responses(I have the unset cookie from backend responses). Could you please > let me know the reason. > > 2) If the approach is ok, please advise on any issues are related to this > approach. > > 3) I am not adding any specific value in hash block, so requests are cached > only based on req-url or IP. hope that is right. > > > ================================= > sub vcl_recv { > 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, > ";(COOKIE1|COOKIE2)=", "; \1="); > set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", ""); > set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", ""); > > if (req.http.Cookie == "") { > unset req.http.Cookie; > } > } > } > > ================================= > > > _______________________________________________ > varnish-misc mailing list > [email protected] <mailto:[email protected]> > https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc > <https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc> > > _______________________________________________ > varnish-misc mailing list > [email protected] > https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
_______________________________________________ varnish-misc mailing list [email protected] https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
