<div dir="ltr"><div>Hi,</div><div><br></div><div>> Is it because I have one url -</div><div>> - that can return 2 responses based on browser</div><div><br></div><div>That's the one, you need to tell varnish to care about the browser. You have two ways to do that: either put that in in the hash key directly, or put it in in a header, and tell that to varnish via the vary header.</div><div><br></div><div>First option looks like this:</div><div><br></div><div>sub vcl_recv {</div><div>  if (SOME_TEST_TO_CHECK_ITS_SAFARI) {</div><div>      set req.http.browser = "safari";</div><div>  } else {</div><div>    set req.http.browser = "somethingelse";</div><div>  }</div><div>}</div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><br></div><div>sub vcl_hash {</div><div>  hash_data(req.http.browser);</div><div>  # do NOT return, let the built-in vcl run</div><div>}</div><div><br></div><div>The pro is that you don't need to change the backend, the con is that if you purge, you have to purge twice because they are two different objects.</div><div><br></div><div>The second option is to tell varnish that the browser is important, but just a variant of the same object:</div><div><br></div><div><div>sub vcl_recv {</div><div>  if (SOME_TEST_TO_CHECK_ITS_SAFARI) {</div><div>      set req.http.browser = "safari";</div><div>  } else {</div><div>    set req.http.browser = "somethingelse";</div><div>  }</div><div>}</div><div><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><br></div><div>sub vcl_backend_response {</div><div>  set beresp.http.vary = beresp.http.vary + ",browser";</div><div>}</div></div></div></div></div><div><br></div><div>Note that you can also have the backend return the vary header for you directly</div><div><br></div><div>There are a couple of cleaner versions, but they are a bit more involved, so let's start with that.</div><div><br></div><div>Side note: I understand where you are coming from with the std.log debugging, but that info is actually super redundant with what's in the log.</div><div><br></div><div>-- <br></div>Guillaume Quintard<br></div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Jan 20, 2019 at 4:14 AM Maninder Singh <<a href="mailto:mandys@gmail.com">mandys@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi Everyone,<div><br></div><div>I am unable to get caching to work in a particular scenario.</div><div><br></div><div>I need to cache the url eg: /app/profile/GDPR1?hostingUrl=http%3A%2F%<a href="http://2Fitvidffya.blogspot.com" target="_blank">2Fitvidffya.blogspot.com</a>%2F2019%2F01%2Fvar-nish-issue-fix.html</div><div><br></div><div>However, this is embedded in a 3rd party site (<a href="http://www.anotherdomain.com" target="_blank">www.anotherdomain.com</a> calls <a href="http://mydomain.com" target="_blank">mydomain.com</a> in iframe ) so on Apple Safari we can't drop cookies ( as 3rd party cookies are blocked by default ).</div><div><br></div><div>As a result, for Apple Safari, when this url is hit, our backend returns top.location.href='someurlonoursite_to_set_cookie' which is fired in context of 3rd party site since they embed using our javascript.</div><div><br></div><div>This way a cookie is dropped on our domain and user gets back to the url inside the iframe.</div><div><br></div><div>Now, when I hit this url in chrome, it always picks up top.location.href='....' as it got cached by safari.</div><div><br></div><div>But, chrome was supposed to get the actual page content since it's not blocking 3rd party cookies.</div><div><br></div><div>So, I went ahead and added a custom header, "store" for cases of apple safari in our backend.</div><div>I skip unsetting cookie (hence varnish cache) for this url in this case.</div><div><br></div><div>But, it still doesn't cache on chrome in subsequent hits.</div><div><br></div><div>Always goes to backend, never goes to the cache.</div><div><br></div><div>Is it because I have one url -</div><div>- that can return 2 responses based on browser</div><div>- I told it to not cache first time when store header was there, but when store header is not there i ask it to cache it.</div><div><br></div><div>Still doesn't work.</div><div><br></div><div>Config</div><div><br></div><div><div>sub vcl_recv {</div><div>    std.log("vtglog: in vcl_recv " + req.url);</div><div>    # Only cache GET or HEAD requests. This makes sure the POST requests are always passed.<br></div><div>    if (req.method != "GET" && req.method != "HEAD") {</div><div>        return (pass);</div><div>    }</div><div><br></div><div>    if(req.http.host == "<a href="http://sqa03.mydomain.com" target="_blank">sqa03.mydomain.com</a>" && req.url ~ "/app/profile"){</div><div>        std.log("vtglog: unsetting cookies");</div><div>        unset req.http.cookie;</div><div>    } else{</div><div>        return(pass);</div><div>    }</div><div><br></div><div>    if (req.http.Authorization) {</div><div>        # Not cacheable by default</div><div>        return (pass);</div><div>    }</div><div>}</div><div><br></div><div>sub vcl_backend_response {</div><div>    std.log("vtglog: vcl_backend_response" + bereq.url) ;</div><div>    # Happens after we have read the response headers from the backend.</div><div>    #</div><div>    # Here you clean the response headers, removing silly Set-Cookie headers</div><div>    # and other mistakes your backend does.</div><div>    if (bereq.http.host == "<a href="http://sqa03.mydomain.com" target="_blank">sqa03.mydomain.com</a>" && bereq.url ~ "/app/profile") {</div><div>        std.log("vtglog: inside condition in backend response");</div><div>        std.log("vtglog: store header value is " + beresp.http.store);</div><div>        if ( beresp.http.Set-Cookie ) {</div><div>            if ( !beresp.http.store ) {</div><div>                std.log("vtglog: since no store headers, cache it by unsetting cookies");</div><div>                unset beresp.http.Set-Cookie;</div><div>            } else {</div><div>                std.log("vtglog: store header found, dont cache");</div><div>            }</div><div>        }</div><div>    }</div><div><br></div><div>    if (beresp.status == 301 || beresp.status == 302) {</div><div>        set beresp.http.Location = regsub(beresp.http.Location, ":[0-9]+", "");</div><div>    }</div><div><br></div><div>    # Don't cache 50x responses</div><div>    if (beresp.status == 500 || beresp.status == 502 || beresp.status == 503 || beresp.status == 504) {</div><div>        return (abandon);</div><div>    }</div><div>}</div></div></div></div></div>
_______________________________________________<br>
varnish-misc mailing list<br>
<a href="mailto:varnish-misc@varnish-cache.org" target="_blank">varnish-misc@varnish-cache.org</a><br>
<a href="https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc" rel="noreferrer" target="_blank">https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc</a><br>
</blockquote></div>