Skip to content

Commit

Permalink
ESI in varnishtest
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscovg committed Dec 23, 2015
1 parent 10cadb7 commit aaabeb4
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 16 deletions.
29 changes: 16 additions & 13 deletions .aspell.en.pws
@@ -1,4 +1,4 @@
personal_ws-1.1 en 428
personal_ws-1.1 en 431
ajax
apache
google
Expand All @@ -16,8 +16,8 @@ CET
github
delim
arg
https
HTTP's
https
VMODs
Naghibi
nosni
Expand Down Expand Up @@ -120,8 +120,8 @@ cliok
sudo
txreq
RESTful
IPv
ipv
IPv
Argv
uint
Acceptor
Expand All @@ -137,36 +137,39 @@ 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
cowsay
Kamp
codename
LRU
ReqURL
ReqUrl
ReqURL
asts
SELinux
LTS
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -295,8 +298,8 @@ url
testbed
hdrbytes
Arianna
VLU
utf
VLU
BereqURL
malloc
dotMobi's
Expand Down Expand Up @@ -382,8 +385,8 @@ ACLs
js
toolate
bodybytes
nd
lN
nd
kqueue
DSMS
RespHeader
Expand Down Expand Up @@ -414,8 +417,8 @@ localhost
vstatdprobe
Karstensen
varnishlog
ETag
Etag
ETag
substring
noverify
AUTOEXTEND
Expand Down
39 changes: 36 additions & 3 deletions varnish_book.rst
Expand Up @@ -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"
Expand All @@ -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()``::

Expand Down Expand Up @@ -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 ``<!--esi <esi:include src="/body"/> -->``, it triggers a request with URL ``/body``.
The result of this request replaces the ``<!--esi -->`` 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<html>\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
..................

Expand Down Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions vtc/e00004.vtc
@@ -0,0 +1,32 @@
varnishtest "ESI commented include"

server s1 {
rxreq
txresp -body {
<html>
Before include
<!--esi <esi:include src="/body"/> -->
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

0 comments on commit aaabeb4

Please sign in to comment.