From aaabeb451b1922733434c2748909c30eaddb1b9e Mon Sep 17 00:00:00 2001 From: franciscovg Date: Wed, 23 Dec 2015 18:15:40 +0100 Subject: [PATCH] ESI in varnishtest --- .aspell.en.pws | 29 ++++++++++++++++------------- varnish_book.rst | 39 ++++++++++++++++++++++++++++++++++++--- vtc/e00004.vtc | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 16 deletions(-) create mode 100644 vtc/e00004.vtc diff --git a/.aspell.en.pws b/.aspell.en.pws index 81ce22f..8503e69 100644 --- a/.aspell.en.pws +++ b/.aspell.en.pws @@ -1,4 +1,4 @@ -personal_ws-1.1 en 428 +personal_ws-1.1 en 431 ajax apache google @@ -16,8 +16,8 @@ CET github delim arg -https HTTP's +https VMODs Naghibi nosni @@ -120,8 +120,8 @@ cliok sudo txreq RESTful -IPv ipv +IPv Argv uint Acceptor @@ -137,27 +137,30 @@ clierr LFU metadata saintmode -FreeBSD freebsd +FreeBSD gunzip linux Economization NaN RCVTIMEO Haavi +tBefore Aondio enmod mgt releasever -respstatus RespStatus +respstatus vmodtool getNonMasqueraded -HashTwo hashtwo +HashTwo +tIncluded DDoS workspace subdomains +tAfter backend extendible WorkThread @@ -165,8 +168,8 @@ cowsay Kamp codename LRU -ReqURL ReqUrl +ReqURL asts SELinux LTS @@ -247,19 +250,19 @@ helloworldtest varnishapi ubuntu Footbar -rst VBE +rst VCA -src vcc +src recv subrequest util SQL VDD VBP -vcl VAV +vcl VXIDs TLS setsebool @@ -295,8 +298,8 @@ url testbed hdrbytes Arianna -VLU utf +VLU BereqURL malloc dotMobi's @@ -382,8 +385,8 @@ ACLs js toolate bodybytes -nd lN +nd kqueue DSMS RespHeader @@ -414,8 +417,8 @@ localhost vstatdprobe Karstensen varnishlog -ETag Etag +ETag substring noverify AUTOEXTEND diff --git a/varnish_book.rst b/varnish_book.rst index 3796e1f..ff0f046 100644 --- a/varnish_book.rst +++ b/varnish_book.rst @@ -5938,7 +5938,7 @@ Solution: Handle Cookies with ``Vary`` in ``varnishtest`` ``Vary`` and ``hash_data()`` might behave very similar at first sight and they might even seem like alternatives for handling cookies. However, cached objects are referenced in different ways. - If Varnish is forced to store responeses with cookies, ``Vary`` ensures that Varnish stores resources per URL and Cookie. + If Varnish is forced to store responses with cookies, ``Vary`` ensures that Varnish stores resources per URL and Cookie. If ``Vary: Cookie`` is used, objects are purged in this way:: txreq -req PURGE -url "/cookie.php" @@ -5955,8 +5955,8 @@ Solution: Handle Cookies with ``hash_data()`` in ``varnishtest`` .. container:: handout - ``hash_data(req.http.Cookie)`` adds the request header field ``Cookie`` to the hashkey. - So Varnish can discern between backend responeses linked to a specific request header field. + ``hash_data(req.http.Cookie)`` adds the request header field ``Cookie`` to the hash key. + So Varnish can discern between backend responses linked to a specific request header field. To purge cached objects in this case, you have to specify the header field used in ``hash_data()``:: @@ -6075,6 +6075,38 @@ This is done in `vcl_recv`. Varnish outputs ESI parsing errors in ``varnishstat`` and ``varnishlog``. +Understanding ESI in ``varnishtest`` +.................................... + +**Varnish-Cache/bin/varnishtest/tests/e00004.vtc**: + +.. include:: vtc/e00004.vtc + :literal: + +.. container:: handout + + ``e00004.vtc`` shows how ESI substitution works. + When Varnish reads ````, it triggers a request with URL ``/body``. + The result of this request replaces the ```` tag. + + We have counted the expected body length after the substitution and assert it in the VTC, but if you do not trust us, you can easily see the replacement by executing:: + + varnishtest -v e00004.vtc | grep "chunk|" + + In the result:: + + **** c1 0.4 chunk| \n + **** c1 0.4 chunk| \t\t\n + **** c1 0.4 chunk| \t\tBefore include\n + **** c1 0.4 chunk| \t\t + **** c1 0.4 chunk| \n + **** c1 0.4 chunk| \t\tIncluded file\n + **** c1 0.4 chunk| \t \n + **** c1 0.4 chunk| \t\tAfter include\n + **** c1 0.4 chunk| \t + + you can see the HTML document after ESI has been processed. + Example: Using ESI .................. @@ -6119,6 +6151,7 @@ Exercise: Enable ESI and Cookies You may also want to try ``PURGE``. If so, you have to purge each of the objects, because purging just ``/esi-top.php`` does not purge ``/esi-user.php``. + .. bookmark: .. TODO for the author: To create a solution for this exercise. Testing ESI without Varnish diff --git a/vtc/e00004.vtc b/vtc/e00004.vtc new file mode 100644 index 0000000..be1dce6 --- /dev/null +++ b/vtc/e00004.vtc @@ -0,0 +1,32 @@ +varnishtest "ESI commented include" + +server s1 { + rxreq + txresp -body { + + Before include + + After include + } + rxreq + expect req.url == "/body" + txresp -body { + Included file + } +} -start + +varnish v1 -vcl+backend { + sub vcl_backend_response { + set beresp.do_esi = true; + } +} -start + +client c1 { + txreq + rxresp + expect resp.status == 200 + expect resp.bodylen == 67 +} + +client c1 -run +varnish v1 -expect esi_errors == 0