<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>Hi,</p>
<p>I am trying to set Varnish to cache content when login cookie is
not present. Hence, I have modified the following subroutines:</p>
<ul>
<li>vcl_recv: If the login cookie is not present, return hash.</li>
<li>vcl_back_response: If the login cookie is not present, cache
the content (beresp.uncacheable set to false</li>
</ul>
<p>Whenever the vcl_recv is returning hash, varnish is generating
blank page with content-length set 0. If vcl_recv returns pass,
the page is served fine. <br>
</p>
<p>I am new with Varnish and have spent hours figuring out but not
able to. <br>
</p>
<p>Would really appreciate if someone could help with the above.</p>
<p>Thanks,</p>
<p>Pinakee <br>
</p>
<p>Following is the VCL:</p>
<p>sub vcl_recv {<br>
# Happens before we check if we have this in cache already.<br>
#<br>
# Typically you clean up the request here, removing cookies
you don't need,<br>
# rewriting the request, etc.<br>
set req.backend_hint = uwsgi;<br>
<br>
if (req.http.Cookie !~ "jivaana_user=") {<br>
return(hash);<br>
}<br>
}<br>
<br>
sub vcl_backend_response {<br>
# Happens after we have read the response headers from the
backend.<br>
#<br>
# Here you clean the response headers, removing silly
Set-Cookie headers<br>
# and other mistakes your backend does.<br>
if (beresp.http.Set-Cookie !~ "jivaana_user=") {<br>
if (beresp.ttl <= 0s) {<br>
set beresp.ttl = 120s;<br>
}<br>
set beresp.uncacheable = false;<br>
return (deliver);<br>
}</p>
<p>Varnish log:</p>
<p><br>
</p>
<p>* << BeReq >> 3 <br>
- Begin bereq 2 fetch<br>
- Timestamp Start: 1463994442.986360 0.000000 0.000000<br>
- BereqMethod GET<br>
- BereqURL /catalogue/<br>
- BereqProtocol HTTP/1.0<br>
- BereqHeader Host: django_test<br>
- BereqHeader Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8<br>
- BereqHeader Upgrade-Insecure-Requests: 1<br>
- BereqHeader User-Agent: Mozilla/5.0 (Macintosh; Intel Mac
OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/50.0.2661.102 Safari/537.36<br>
- BereqHeader Accept-Language: en-US,en;q=0.8<br>
- BereqHeader X-Forwarded-For: 127.0.0.1<br>
- BereqHeader Accept-Encoding: gzip<br>
- BereqProtocol HTTP/1.1<br>
- BereqHeader X-Varnish: 3<br>
- VCL_call BACKEND_FETCH<br>
- VCL_return fetch<br>
- BackendOpen 21 boot.uwsgi 127.0.0.1 9001 127.0.0.1 38213<br>
- Timestamp Bereq: 1463994442.986883 0.000524 0.000524<br>
- Timestamp Beresp: 1463994443.734972 0.748612 0.748088<br>
- BerespProtocol HTTP/1.1<br>
- BerespStatus 200<br>
- BerespReason OK<br>
- BerespHeader Expires: Mon, 23 May 2016 09:07:23 GMT<br>
- BerespHeader Vary: Cookie<br>
- BerespHeader Last-Modified: Mon, 23 May 2016 09:07:23 GMT<br>
- BerespHeader Cache-Control: max-age=0<br>
- BerespHeader X-Frame-Options: SAMEORIGIN<br>
- BerespHeader Content-Type: text/html; charset=utf-8<br>
- BerespHeader Set-Cookie:
csrftoken=5BUZRL4gdO7uTDtWXnbqQko3CelDmOAg; expires=Mon,
22-May-2017 09:07:23 GMT; Max-Age=31449600; Path=/<br>
- BerespHeader Date: Mon, 23 May 2016 09:07:23 GMT<br>
- TTL RFC 0 10 -1 1463994444 1463994444 1463994443
1463994443 0<br>
- VCL_call BACKEND_RESPONSE<br>
- TTL VCL 120 10 0 1463994444<br>
- VCL_return deliver<br>
- Storage file s0<br>
- ObjProtocol HTTP/1.1<br>
- ObjStatus 200<br>
- ObjReason OK<br>
- ObjHeader Expires: Mon, 23 May 2016 09:07:23 GMT<br>
- ObjHeader Vary: Cookie<br>
- ObjHeader Last-Modified: Mon, 23 May 2016 09:07:23 GMT<br>
- ObjHeader Cache-Control: max-age=0<br>
- ObjHeader X-Frame-Options: SAMEORIGIN<br>
- ObjHeader Content-Type: text/html; charset=utf-8<br>
- ObjHeader Set-Cookie:
csrftoken=5BUZRL4gdO7uTDtWXnbqQko3CelDmOAg; expires=Mon,
22-May-2017 09:07:23 GMT; Max-Age=31449600; Path=/<br>
- ObjHeader Date: Mon, 23 May 2016 09:07:23 GMT<br>
- Fetch_Body 0 none -<br>
- BackendReuse 21 boot.uwsgi<br>
- Timestamp BerespBody: 1463994443.735229 0.748869 0.000257<br>
- Length 0<br>
- BereqAcct 393 0 393 336 0 336<br>
- End <br>
<br>
* << Request >> 2 <br>
- Begin req 1 rxreq<br>
- Timestamp Start: 1463994442.986091 0.000000 0.000000<br>
- Timestamp Req: 1463994442.986091 0.000000 0.000000<br>
- ReqStart 127.0.0.1 56147<br>
- ReqMethod GET<br>
- ReqURL /catalogue/<br>
- ReqProtocol HTTP/1.0<br>
- ReqHeader Host: django_test<br>
- ReqHeader Connection: close<br>
- ReqHeader Cache-Control: max-age=0<br>
- ReqHeader Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8<br>
- ReqHeader Upgrade-Insecure-Requests: 1<br>
- ReqHeader User-Agent: Mozilla/5.0 (Macintosh; Intel Mac
OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/50.0.2661.102 Safari/537.36<br>
- ReqHeader Accept-Encoding: gzip, deflate, sdch<br>
- ReqHeader Accept-Language: en-US,en;q=0.8<br>
- ReqHeader Cookie: pagemap=0,0,0,0,0,1,0';
pagemap=0,0,0,0,0,0,0; jivaana_country=IN; mp_mixpanel__c=1;
mp_mixpanel__c3=2; mp_mixpanel__c4=2; mp_mixpanel__c5=0;
_ga=GA1.1.1762020660.1447765749;
mp_774636c1ed2371eaf99455f71871069c_mixpanel=%7B%22distinct_id%22%3A%20<br>
- ReqHeader If-Modified-Since: Mon, 23 May 2016 09:03:11
GMT<br>
- ReqHeader X-Forwarded-For: 127.0.0.1<br>
- VCL_call RECV<br>
- ReqUnset Cookie: pagemap=0,0,0,0,0,1,0';
pagemap=0,0,0,0,0,0,0; jivaana_country=IN; mp_mixpanel__c=1;
mp_mixpanel__c3=2; mp_mixpanel__c4=2; mp_mixpanel__c5=0;
_ga=GA1.1.1762020660.1447765749;
mp_774636c1ed2371eaf99455f71871069c_mixpanel=%7B%22distinct_id%22%3A%20<br>
- VCL_return hash<br>
- ReqUnset Accept-Encoding: gzip, deflate, sdch<br>
- ReqHeader Accept-Encoding: gzip<br>
- VCL_call HASH<br>
- VCL_return lookup<br>
- VCL_call MISS<br>
- VCL_return fetch<br>
- Link bereq 3 fetch<br>
- Timestamp Fetch: 1463994443.735287 0.749196 0.749196<br>
- RespProtocol HTTP/1.1<br>
- RespStatus 200<br>
- RespReason OK<br>
- RespHeader Expires: Mon, 23 May 2016 09:07:23 GMT<br>
- RespHeader Vary: Cookie<br>
- RespHeader Last-Modified: Mon, 23 May 2016 09:07:23 GMT<br>
- RespHeader Cache-Control: max-age=0<br>
- RespHeader X-Frame-Options: SAMEORIGIN<br>
- RespHeader Content-Type: text/html; charset=utf-8<br>
- RespHeader Set-Cookie:
csrftoken=5BUZRL4gdO7uTDtWXnbqQko3CelDmOAg; expires=Mon,
22-May-2017 09:07:23 GMT; Max-Age=31449600; Path=/<br>
- RespHeader Date: Mon, 23 May 2016 09:07:23 GMT<br>
- RespHeader X-Varnish: 2<br>
- RespHeader Age: 0<br>
- RespHeader Via: 1.1 varnish-v4<br>
- VCL_call DELIVER<br>
- VCL_return deliver<br>
- Timestamp Process: 1463994443.735341 0.749249 0.000054<br>
- RespHeader Accept-Ranges: bytes<br>
- RespHeader Content-Length: 0<br>
- Debug "RES_MODE 2"<br>
- RespHeader Connection: close<br>
- Timestamp Resp: 1463994443.735410 0.749319 0.000070<br>
- ReqAcct 929 0 929 476 0 476<br>
- End <br>
<br>
* << Session >> 1 <br>
- Begin sess 0 HTTP/1<br>
- SessOpen 127.0.0.1 56147 0.0.0.0:9003 127.0.0.1 9003
1463994442.985890 18<br>
- Link req 2 rxreq<br>
- SessClose RESP_CLOSE 0.750<br>
- End <br>
<br>
</p>
</body>
</html>