Varnish delivering blank page (content-length=0)

Pinakee BIswas pinakee at waltzz.com
Mon May 23 11:23:13 CEST 2016


Hi,

I am trying to set Varnish to cache content when login cookie is not 
present. Hence, I have modified the following subroutines:

  * vcl_recv: If the login cookie is not present, return hash.
  * vcl_back_response: If the login cookie is not present, cache the
    content (beresp.uncacheable set to false

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.

I am new with Varnish and have spent hours figuring out but not able to.

Would really appreciate if someone could help with the above.

Thanks,

Pinakee

Following is the VCL:

sub vcl_recv {
     # Happens before we check if we have this in cache already.
     #
     # Typically you clean up the request here, removing cookies you 
don't need,
     # rewriting the request, etc.
     set req.backend_hint = uwsgi;

    if (req.http.Cookie !~ "jivaana_user=") {
         return(hash);
     }
}

sub vcl_backend_response {
     # Happens after we have read the response headers from the backend.
     #
     # Here you clean the response headers, removing silly Set-Cookie 
headers
     # and other mistakes your backend does.
     if (beresp.http.Set-Cookie !~ "jivaana_user=") {
         if (beresp.ttl <= 0s) {
                 set beresp.ttl = 120s;
         }
         set beresp.uncacheable = false;
         return (deliver);
}

Varnish log:


*   << BeReq    >> 3
-   Begin          bereq 2 fetch
-   Timestamp      Start: 1463994442.986360 0.000000 0.000000
-   BereqMethod    GET
-   BereqURL       /catalogue/
-   BereqProtocol  HTTP/1.0
-   BereqHeader    Host: django_test
-   BereqHeader    Accept: 
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
-   BereqHeader    Upgrade-Insecure-Requests: 1
-   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
-   BereqHeader    Accept-Language: en-US,en;q=0.8
-   BereqHeader    X-Forwarded-For: 127.0.0.1
-   BereqHeader    Accept-Encoding: gzip
-   BereqProtocol  HTTP/1.1
-   BereqHeader    X-Varnish: 3
-   VCL_call       BACKEND_FETCH
-   VCL_return     fetch
-   BackendOpen    21 boot.uwsgi 127.0.0.1 9001 127.0.0.1 38213
-   Timestamp      Bereq: 1463994442.986883 0.000524 0.000524
-   Timestamp      Beresp: 1463994443.734972 0.748612 0.748088
-   BerespProtocol HTTP/1.1
-   BerespStatus   200
-   BerespReason   OK
-   BerespHeader   Expires: Mon, 23 May 2016 09:07:23 GMT
-   BerespHeader   Vary: Cookie
-   BerespHeader   Last-Modified: Mon, 23 May 2016 09:07:23 GMT
-   BerespHeader   Cache-Control: max-age=0
-   BerespHeader   X-Frame-Options: SAMEORIGIN
-   BerespHeader   Content-Type: text/html; charset=utf-8
-   BerespHeader   Set-Cookie: 
csrftoken=5BUZRL4gdO7uTDtWXnbqQko3CelDmOAg; expires=Mon, 22-May-2017 
09:07:23 GMT; Max-Age=31449600; Path=/
-   BerespHeader   Date: Mon, 23 May 2016 09:07:23 GMT
-   TTL            RFC 0 10 -1 1463994444 1463994444 1463994443 1463994443 0
-   VCL_call       BACKEND_RESPONSE
-   TTL            VCL 120 10 0 1463994444
-   VCL_return     deliver
-   Storage        file s0
-   ObjProtocol    HTTP/1.1
-   ObjStatus      200
-   ObjReason      OK
-   ObjHeader      Expires: Mon, 23 May 2016 09:07:23 GMT
-   ObjHeader      Vary: Cookie
-   ObjHeader      Last-Modified: Mon, 23 May 2016 09:07:23 GMT
-   ObjHeader      Cache-Control: max-age=0
-   ObjHeader      X-Frame-Options: SAMEORIGIN
-   ObjHeader      Content-Type: text/html; charset=utf-8
-   ObjHeader      Set-Cookie: 
csrftoken=5BUZRL4gdO7uTDtWXnbqQko3CelDmOAg; expires=Mon, 22-May-2017 
09:07:23 GMT; Max-Age=31449600; Path=/
-   ObjHeader      Date: Mon, 23 May 2016 09:07:23 GMT
-   Fetch_Body     0 none -
-   BackendReuse   21 boot.uwsgi
-   Timestamp      BerespBody: 1463994443.735229 0.748869 0.000257
-   Length         0
-   BereqAcct      393 0 393 336 0 336
-   End

*   << Request  >> 2
-   Begin          req 1 rxreq
-   Timestamp      Start: 1463994442.986091 0.000000 0.000000
-   Timestamp      Req: 1463994442.986091 0.000000 0.000000
-   ReqStart       127.0.0.1 56147
-   ReqMethod      GET
-   ReqURL         /catalogue/
-   ReqProtocol    HTTP/1.0
-   ReqHeader      Host: django_test
-   ReqHeader      Connection: close
-   ReqHeader      Cache-Control: max-age=0
-   ReqHeader      Accept: 
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
-   ReqHeader      Upgrade-Insecure-Requests: 1
-   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
-   ReqHeader      Accept-Encoding: gzip, deflate, sdch
-   ReqHeader      Accept-Language: en-US,en;q=0.8
-   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
-   ReqHeader      If-Modified-Since: Mon, 23 May 2016 09:03:11 GMT
-   ReqHeader      X-Forwarded-For: 127.0.0.1
-   VCL_call       RECV
-   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
-   VCL_return     hash
-   ReqUnset       Accept-Encoding: gzip, deflate, sdch
-   ReqHeader      Accept-Encoding: gzip
-   VCL_call       HASH
-   VCL_return     lookup
-   VCL_call       MISS
-   VCL_return     fetch
-   Link           bereq 3 fetch
-   Timestamp      Fetch: 1463994443.735287 0.749196 0.749196
-   RespProtocol   HTTP/1.1
-   RespStatus     200
-   RespReason     OK
-   RespHeader     Expires: Mon, 23 May 2016 09:07:23 GMT
-   RespHeader     Vary: Cookie
-   RespHeader     Last-Modified: Mon, 23 May 2016 09:07:23 GMT
-   RespHeader     Cache-Control: max-age=0
-   RespHeader     X-Frame-Options: SAMEORIGIN
-   RespHeader     Content-Type: text/html; charset=utf-8
-   RespHeader     Set-Cookie: 
csrftoken=5BUZRL4gdO7uTDtWXnbqQko3CelDmOAg; expires=Mon, 22-May-2017 
09:07:23 GMT; Max-Age=31449600; Path=/
-   RespHeader     Date: Mon, 23 May 2016 09:07:23 GMT
-   RespHeader     X-Varnish: 2
-   RespHeader     Age: 0
-   RespHeader     Via: 1.1 varnish-v4
-   VCL_call       DELIVER
-   VCL_return     deliver
-   Timestamp      Process: 1463994443.735341 0.749249 0.000054
-   RespHeader     Accept-Ranges: bytes
-   RespHeader     Content-Length: 0
-   Debug          "RES_MODE 2"
-   RespHeader     Connection: close
-   Timestamp      Resp: 1463994443.735410 0.749319 0.000070
-   ReqAcct        929 0 929 476 0 476
-   End

*   << Session  >> 1
-   Begin          sess 0 HTTP/1
-   SessOpen       127.0.0.1 56147 0.0.0.0:9003 127.0.0.1 9003 
1463994442.985890 18
-   Link           req 2 rxreq
-   SessClose      RESP_CLOSE 0.750
-   End

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20160523/b172a2df/attachment-0001.html>


More information about the varnish-misc mailing list