<div dir="ltr">> I know. But, varnishlog has lot of info and this was done so that I could just do varnishlog | grep "vtglog" to see the flow as per my liking :-)<div>> This has now been removed.</div><div><br></div><div>varnishlog -i NameOfTheTag is your friend</div><div><br></div><div>> This should now keep 2 copies of the same url - one for Safari and one for the rest - right ?<br></div><div><br></div><div>Yessir</div><div><br></div><div><div>> What's a good way to check how many cache copies are present for a url ?</div><div><br></div><div>that's not something you can do at the moment</div><br class="gmail-Apple-interchange-newline"></div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>-- <br></div>Guillaume Quintard<br></div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jan 22, 2019 at 8:54 PM 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">Thank you Guillaume for your suggestions.<div><br></div><div>This seemed to have worked.</div><div><br></div><div>I am now using the following vcl config.</div><div><br></div><div>>> 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>I know. But, varnishlog has lot of info and this was done so that I could just do varnishlog | grep "vtglog" to see the flow as per my liking :-)</div><div>This has now been removed.</div><div><br></div><div>This should now keep 2 copies of the same url - one for Safari and one for the rest - right ?</div><div><br></div><div>Question:</div><div>What's a good way to check how many cache copies are present for a url ?</div><div><br></div><div>Once again thank you for your help!</div><div><br></div><div>- Mandy.</div><div><br></div><div><div>vcl 4.0;</div><div><br></div><div># Default backend definition. Set this to point to your content server.<br></div><div>backend default {</div><div>    .host = "127.0.0.1";</div><div>    .port = "8080";</div><div>}</div><div><br></div><div>sub vcl_recv {</div><div>    if (req.http.User-Agent ~ "Safari") {<br></div><div>        if (req.http.User-Agent ~ "Chrome") {</div><div>            set req.http.browser = "other";</div><div>        } else {<br></div><div>            set req.http.browser = "safari";</div><div>        }<br></div><div>    } else {</div><div>        set req.http.browser = "other";<br></div><div>    }</div><div><br></div><div>    # Only cache GET or HEAD requests. This makes sure the POST requests are always passed.</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>        unset req.http.cookie;<br></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><div><div><br></div><div>sub vcl_backend_response {</div><div>    # Happens after we have read the response headers from the backend.<br></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>        set beresp.ttl = 180 s;</div><div>        if ( beresp.http.Set-Cookie ) {<br></div><div>                unset beresp.http.Set-Cookie;<br></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><br></div><div>sub vcl_hash {</div><div>    hash_data(req.http.browser);<br></div><div>}</div><div><br></div><div>sub vcl_deliver {</div><div>    # Happens when we have all the pieces we need, and are about to send the</div><div>    # response to the client.</div><div>    #</div><div>    # You can do accounting or modifying the final object here.</div><div>    if (obj.hits > 0) {</div><div>      # Add debug header to see if it's a HIT/MISS and the number of hits, disable when not needed</div><div>      set resp.http.X-Cache = "HIT";</div><div>    } else {</div><div>      set resp.http.X-Cache = "MISS";</div><div>    }</div><div><br></div><div>    set resp.http.X-Cache-Hits = obj.hits;</div><div>}</div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail-m_-8903149371473169762gmail_attr">On Mon, 21 Jan 2019 at 09:09, Guillaume Quintard <<a href="mailto:guillaume@varnish-software.com" target="_blank">guillaume@varnish-software.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>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-m_-8903149371473169762gmail-m_3417690376251073884gmail_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-m_-8903149371473169762gmail-m_3417690376251073884gmail_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-m_-8903149371473169762gmail-m_3417690376251073884gmail_attr">On Sun, Jan 20, 2019 at 4:14 AM Maninder Singh <<a href="mailto:mandys@gmail.com" target="_blank">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>
</blockquote></div>
</blockquote></div>