<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">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">www.anotherdomain.com</a> calls <a href="http://mydomain.com">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">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">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>