<div dir="ltr">Hi,<div><br></div><div>As per the link <a href="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</a>, 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.<br></div><div><br></div><div>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. </div><div><br></div><div>2) If the approach is ok, please advise on any issues are related to this approach.</div><div><br></div><div>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.<br></div><div><br></div><div><br></div><div>=================================</div><div><pre><span class="gmail-n">sub</span> <span class="gmail-n">vcl_recv</span> <span class="gmail-p">{</span>
<span class="gmail-k">if</span> <span class="gmail-p">(</span><span class="gmail-n">req</span><span class="gmail-o">.</span><span class="gmail-n">http</span><span class="gmail-o">.</span><span class="gmail-n">Cookie</span><span class="gmail-p">)</span> <span class="gmail-p">{</span>
<span class="gmail-nb">set</span> <span class="gmail-n">req</span><span class="gmail-o">.</span><span class="gmail-n">http</span><span class="gmail-o">.</span><span class="gmail-n">Cookie</span> <span class="gmail-o">=</span> <span class="gmail-s2">";"</span> <span class="gmail-o">+</span> <span class="gmail-n">req</span><span class="gmail-o">.</span><span class="gmail-n">http</span><span class="gmail-o">.</span><span class="gmail-n">Cookie</span><span class="gmail-p">;</span>
<span class="gmail-nb">set</span> <span class="gmail-n">req</span><span class="gmail-o">.</span><span class="gmail-n">http</span><span class="gmail-o">.</span><span class="gmail-n">Cookie</span> <span class="gmail-o">=</span> <span class="gmail-n">regsuball</span><span class="gmail-p">(</span><span class="gmail-n">req</span><span class="gmail-o">.</span><span class="gmail-n">http</span><span class="gmail-o">.</span><span class="gmail-n">Cookie</span><span class="gmail-p">,</span> <span class="gmail-s2">"; +"</span><span class="gmail-p">,</span> <span class="gmail-s2">";"</span><span class="gmail-p">);</span>
<span class="gmail-nb">set</span> <span class="gmail-n">req</span><span class="gmail-o">.</span><span class="gmail-n">http</span><span class="gmail-o">.</span><span class="gmail-n">Cookie</span> <span class="gmail-o">=</span> <span class="gmail-n">regsuball</span><span class="gmail-p">(</span><span class="gmail-n">req</span><span class="gmail-o">.</span><span class="gmail-n">http</span><span class="gmail-o">.</span><span class="gmail-n">Cookie</span><span class="gmail-p">,</span> <span class="gmail-s2">";(COOKIE1|COOKIE2)="</span><span class="gmail-p">,</span> <span class="gmail-s2">"; </span><span class="gmail-se">\1</span><span class="gmail-s2">="</span><span class="gmail-p">);</span>
<span class="gmail-nb">set</span> <span class="gmail-n">req</span><span class="gmail-o">.</span><span class="gmail-n">http</span><span class="gmail-o">.</span><span class="gmail-n">Cookie</span> <span class="gmail-o">=</span> <span class="gmail-n">regsuball</span><span class="gmail-p">(</span><span class="gmail-n">req</span><span class="gmail-o">.</span><span class="gmail-n">http</span><span class="gmail-o">.</span><span class="gmail-n">Cookie</span><span class="gmail-p">,</span> <span class="gmail-s2">";[^ ][^;]*"</span><span class="gmail-p">,</span> <span class="gmail-s2">""</span><span class="gmail-p">);</span>
<span class="gmail-nb">set</span> <span class="gmail-n">req</span><span class="gmail-o">.</span><span class="gmail-n">http</span><span class="gmail-o">.</span><span class="gmail-n">Cookie</span> <span class="gmail-o">=</span> <span class="gmail-n">regsuball</span><span class="gmail-p">(</span><span class="gmail-n">req</span><span class="gmail-o">.</span><span class="gmail-n">http</span><span class="gmail-o">.</span><span class="gmail-n">Cookie</span><span class="gmail-p">,</span> <span class="gmail-s2">"^[; ]+|[; ]+$"</span><span class="gmail-p">,</span> <span class="gmail-s2">""</span><span class="gmail-p">);</span>
<span class="gmail-k">if</span> <span class="gmail-p">(</span><span class="gmail-n">req</span><span class="gmail-o">.</span><span class="gmail-n">http</span><span class="gmail-o">.</span><span class="gmail-n">Cookie</span> <span class="gmail-o">==</span> <span class="gmail-s2">""</span><span class="gmail-p">)</span> <span class="gmail-p">{</span>
<span class="gmail-n">unset</span> <span class="gmail-n">req</span><span class="gmail-o">.</span><span class="gmail-n">http</span><span class="gmail-o">.</span><span class="gmail-n">Cookie</span><span class="gmail-p">;</span>
<span class="gmail-p">}</span>
<span class="gmail-p">}</span>
<span class="gmail-p">}</span></pre><pre><span class="gmail-p"><br class="gmail-Apple-interchange-newline"><span style="font-family:arial,sans-serif;white-space:normal">=================================</span><br></span></pre></div></div>