<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <p>Hi Per Buer,</p>
    <p>Thanks for the response and suggestion. I agree that caching with
      Cookies is a dangerous thing as cookies are mostly user specific
      and caching could leak them.</p>
    <p>But the challenge here is that we have few cookies which would be
      needed by the backend. For example, we use a cookie which
      specifies the country for the client/user. The cookie is used by
      the backend  to figure out the country the user is in. But then I
      would like to cache the pages for a specific country. So, all the
      pages for users in US should be cached with a key using the
      country cookie - was trying this:</p>
    <p>sub vcl_hash {<br>
           if (req.http.cookie ~ "user_country=") {<br>
              set req.http.X-TMP = regsub(req.http.cookie,
      ".*user_country=([^;]+);.*", "\1");<br>
              hash_data(req.http.X-TMP);<br>
              unset req.http.X-TMP;<br>
           }<br>
      }<br>
    </p>
    <p>I am not clear if unset strips the cookies so that they don't get
      cached or they are completely removed from the Cookie header
      before the request being passed to the backend. If it's former, it
      would be nice.</p>
    <p>Any suggestion how to handle the above scenario would be great.<br>
    </p>
    <p>Thanks,</p>
    <p>Pinakee<br>
    </p>
    <div class="moz-cite-prefix">On 24/05/16 2:28 pm, Per Buer wrote:<br>
    </div>
    <blockquote
cite="mid:CAOXZevC6D-sziYRqnufyzQ+vKDNzBQsVt02TtU_+=-SvQ5oxWw@mail.gmail.com"
      type="cite">
      <div dir="ltr"><br>
        <div class="gmail_extra"><br>
          <div class="gmail_quote">On Tue, May 24, 2016 at 10:46 AM,
            Pinakee BIswas <span dir="ltr"><<a
                moz-do-not-send="true" href="mailto:pinakee@waltzz.com"
                target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:pinakee@waltzz.com">pinakee@waltzz.com</a></a>></span> wrote:<br>
            <blockquote class="gmail_quote" style="margin:0 0 0
              .8ex;border-left:1px #ccc solid;padding-left:1ex">
              <div bgcolor="#FFFFFF" text="#000000">
                <div>
                  <div class="h5">
                    <blockquote type="cite">
                      <p>I am trying to set Varnish to cache content
                        when login cookie is not present. Hence, I have
                        modified the following subroutines:</p>
                    </blockquote>
                  </div>
                </div>
              </div>
            </blockquote>
            <div><br>
            </div>
            <div>What you want to do is to modify the request so the
              default VCL will cache it rather than force Varnish to
              cache it. If you force Varnish to cache it Varnish will
              end up caching it with cookies and such. This is
              potentially dangerous.</div>
            <div><br>
            </div>
            <div>So I would recommend something like this in vcl_recv:</div>
            <div><br>
            </div>
            <div>if (req.http.cookie !~ "logged in") {</div>
            <div>    unset req.http.cookie; # strip the cookies - we
              don't need them</div>
            <div>} </div>
            <div><br>
            </div>
            <div> # if there is a cookie here still the default policy
              will make sure the request isn't cached.</div>
            <div><br>
            </div>
            <div><br>
            </div>
            <div><br>
            </div>
            <div>Per.</div>
          </div>
          <div><br>
          </div>
          -- <br>
          <div class="gmail_signature">
            <div dir="ltr">
              <div>
                <div dir="ltr">
                  <table
style="border-bottom-width:1px;padding-top:5px;border-top-style:solid;width:550px;padding-bottom:5px;border-bottom-color:rgb(238,238,238);border-top-width:1px;border-bottom-style:solid;line-height:1.5em;border-top-color:rgb(238,238,238);color:rgb(102,102,102);font-size:12px;font-family:'Helvetica
                    Neue',Arial,sans-serif;margin-top:20px" border="0"
                    cellpadding="0" cellspacing="0">
                    <tbody>
                      <tr>
                        <td width="100"><img moz-do-not-send="true"
                            src="http://www.varnish-software.com/static/media/logo-email.png"></td>
                        <td><font color="#222222"><span
                              style="font-size:14px"><b>Per Buer</b></span></font><br>
                          CTO | Varnish Software AS<br>
                          Cell: <a moz-do-not-send="true"
                            value="+4790181750"
                            style="color:rgb(17,85,204)">+47 95839117</a><br>
                          <span style="font-weight:bold">We Make
                            Websites Fly!<br>
                            <a moz-do-not-send="true"
                              href="https://www.varnish-software.com/"
                              style="color:rgb(17,85,204)"
                              target="_blank">www.varnish-software.com</a></span></td>
                      </tr>
                    </tbody>
                  </table>
                  <br>
                  <div style="color:rgb(136,136,136)"><a
                      moz-do-not-send="true"
                      href="http://info.varnish-software.com/signature"
                      target="_blank"><img moz-do-not-send="true"
                        src="http://files.varnish-software.com/signature.png"></a><br>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
  </body>
</html>