From phk at varnish-cache.org Tue May 1 06:40:00 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Tue, 01 May 2012 08:40:00 +0200 Subject: [master] 9190dc3 Add 16k more thread stack to cater for PCRE-JIT. Message-ID: commit 9190dc3602bb65e4a8423f2defedf62145742641 Author: Poul-Henning Kamp Date: Tue May 1 06:38:54 2012 +0000 Add 16k more thread stack to cater for PCRE-JIT. Polish vre.c a bit with respect to memory management and error messages. diff --git a/bin/varnishd/mgt/mgt_pool.c b/bin/varnishd/mgt/mgt_pool.c index e5d5cd0..986d405 100644 --- a/bin/varnishd/mgt/mgt_pool.c +++ b/bin/varnishd/mgt/mgt_pool.c @@ -215,6 +215,6 @@ const struct parspec WRK_parspec[] = { "This is likely rounded up to a multiple of 4k by the kernel.\n" "The kernel/OS has a lower limit which will be enforced.\n", EXPERIMENTAL, - "32k", "bytes" }, + "48k", "bytes" }, { NULL, NULL, NULL } }; diff --git a/lib/libvarnish/vre.c b/lib/libvarnish/vre.c index ee462c7..2fce5c7 100644 --- a/lib/libvarnish/vre.c +++ b/lib/libvarnish/vre.c @@ -37,17 +37,22 @@ #include "vre.h" +#ifndef PCRE_STUDY_JIT_COMPILE +#define PCRE_STUDY_JIT_COMPILE 0 +#endif + +#if PCRE_MAJOR < 8 || (PCRE_MAJOR == 8 && PCRE_MINOR < 20) +# define pcre_free_study pcre_free +#endif + struct vre { unsigned magic; #define VRE_MAGIC 0xe83097dc pcre *re; pcre_extra *re_extra; + int my_extra; }; -#ifndef PCRE_STUDY_JIT_COMPILE -#define PCRE_STUDY_JIT_COMPILE 0 -#endif - /* * We don't want to spread or even expose the majority of PCRE options * so we establish our own options and implement hard linkage to PCRE @@ -58,29 +63,32 @@ const unsigned VRE_NOTEMPTY = PCRE_NOTEMPTY; vre_t * VRE_compile(const char *pattern, int options, - const char **errptr, int *erroffset) + const char **errptr, int *erroffset) { vre_t *v; *errptr = NULL; *erroffset = 0; ALLOC_OBJ(v, VRE_MAGIC); - if (v == NULL) + if (v == NULL) { + *errptr = "Out of memory for VRE"; return (NULL); + } v->re = pcre_compile(pattern, options, errptr, erroffset, NULL); if (v->re == NULL) { VRE_free(&v); return (NULL); } v->re_extra = pcre_study(v->re, PCRE_STUDY_JIT_COMPILE, errptr); + if (*errptr != NULL) { + VRE_free(&v); + return (NULL); + } if (v->re_extra == NULL) { - if (*errptr != NULL) { - VRE_free(&v); - return (NULL); - } - /* allocate our own, pcre_study can return NULL without it - * being an error */ + /* allocate our own */ v->re_extra = calloc(1, sizeof(pcre_extra)); + v->my_extra = 1; if (v->re_extra == NULL) { + *errptr = "Out of memory for pcre_extra"; VRE_free(&v); return (NULL); } @@ -122,11 +130,13 @@ VRE_free(vre_t **vv) *vv = NULL; CHECK_OBJ(v, VRE_MAGIC); -#ifdef PCRE_CONFIG_JIT - pcre_free_study(v->re_extra); -#else - free(v->re_extra); -#endif - pcre_free(v->re); + if (v->re_extra != NULL) { + if (v->my_extra) + free(v->re_extra); + else + pcre_free_study(v->re_extra); + } + if (v->re != NULL) + pcre_free(v->re); FREE_OBJ(v); } From phk at varnish-cache.org Wed May 2 08:47:32 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Wed, 02 May 2012 10:47:32 +0200 Subject: [master] 1eac7c2 Add code coverage of the RST dumping code Message-ID: commit 1eac7c2672c8afd4ceb3a701240260c2ed294c10 Author: Poul-Henning Kamp Date: Wed May 2 08:47:15 2012 +0000 Add code coverage of the RST dumping code diff --git a/bin/varnishtest/tests/a00009.vtc b/bin/varnishtest/tests/a00009.vtc index 4d35f85..f89231f 100644 --- a/bin/varnishtest/tests/a00009.vtc +++ b/bin/varnishtest/tests/a00009.vtc @@ -1,3 +1,4 @@ -varnishtest "See that the VCL compiler works" +varnishtest "Code coverage of VCL compiler and RSTdump" shell "cd ${topbuild}/bin/varnishd && ./varnishd -b 127.0.0.1:80 -C -n ${tmpdir} > /dev/null 2>&1" +shell "cd ${topbuild}/bin/varnishd && ./varnishd -x dumprst > /dev/null 2>&1" From phk at varnish-cache.org Wed May 2 09:53:35 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Wed, 02 May 2012 11:53:35 +0200 Subject: [master] 227a394 Add a dummy pipe to use for poll(2)'ing the death of varnishd, while we wait for it to establish CLI connection. Message-ID: commit 227a394496d089bc36d03a0e40605010c969019d Author: Poul-Henning Kamp Date: Wed May 2 09:53:09 2012 +0000 Add a dummy pipe to use for poll(2)'ing the death of varnishd, while we wait for it to establish CLI connection. diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c index e493ae7..ed55353 100644 --- a/bin/varnishtest/vtc_varnish.c +++ b/bin/varnishtest/vtc_varnish.c @@ -59,7 +59,7 @@ struct varnish { struct vsb *storage; struct vsb *args; - int fds[4]; + int fds[6]; pid_t pid; pthread_t tp; @@ -365,6 +365,7 @@ varnish_launch(struct varnish *v) vtc_log(v->vl, 3, "CMD: %s", VSB_data(vsb)); AZ(pipe(&v->fds[0])); AZ(pipe(&v->fds[2])); + AZ(pipe(&v->fds[4])); v->pid = fork(); assert(v->pid >= 0); if (v->pid == 0) { @@ -375,8 +376,11 @@ varnish_launch(struct varnish *v) AZ(close(v->fds[1])); AZ(close(v->fds[2])); AZ(close(v->fds[3])); - for (i = 3; i fds[4])); + for (i = 3; i fds[5] != i) + (void)close(i); + } AZ(execl("/bin/sh", "/bin/sh", "-c", VSB_data(vsb), NULL)); exit(1); } else { @@ -384,6 +388,7 @@ varnish_launch(struct varnish *v) } AZ(close(v->fds[0])); AZ(close(v->fds[3])); + AZ(close(v->fds[5])); v->fds[0] = v->fds[2]; v->fds[2] = v->fds[3] = -1; VSB_delete(vsb); @@ -394,8 +399,8 @@ varnish_launch(struct varnish *v) memset(fd, 0, sizeof fd); fd[0].fd = v->cli_fd; fd[0].events = POLLIN; - fd[1].fd = v->fds[0]; - fd[1].events = POLLHUP; + fd[1].fd = v->fds[4]; + fd[1].events = POLLIN|POLLHUP; #ifdef __APPLE__ /* * OSX cannot poll a pipe for POLLHUP only, poll just returns @@ -425,6 +430,7 @@ varnish_launch(struct varnish *v) return; } + AZ(close(v->fds[4])); AZ(close(v->cli_fd)); v->cli_fd = nfd; From phk at varnish-cache.org Wed May 2 10:01:57 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Wed, 02 May 2012 12:01:57 +0200 Subject: [master] 8d2ce2c Revert "Add a dummy pipe to use for poll(2)'ing the death of varnishd, " Message-ID: commit 8d2ce2c25ba26ab38193435cf21ba3d8a18a40cb Author: Poul-Henning Kamp Date: Wed May 2 10:01:26 2012 +0000 Revert "Add a dummy pipe to use for poll(2)'ing the death of varnishd," This reverts commit 227a394496d089bc36d03a0e40605010c969019d. diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c index ed55353..e493ae7 100644 --- a/bin/varnishtest/vtc_varnish.c +++ b/bin/varnishtest/vtc_varnish.c @@ -59,7 +59,7 @@ struct varnish { struct vsb *storage; struct vsb *args; - int fds[6]; + int fds[4]; pid_t pid; pthread_t tp; @@ -365,7 +365,6 @@ varnish_launch(struct varnish *v) vtc_log(v->vl, 3, "CMD: %s", VSB_data(vsb)); AZ(pipe(&v->fds[0])); AZ(pipe(&v->fds[2])); - AZ(pipe(&v->fds[4])); v->pid = fork(); assert(v->pid >= 0); if (v->pid == 0) { @@ -376,11 +375,8 @@ varnish_launch(struct varnish *v) AZ(close(v->fds[1])); AZ(close(v->fds[2])); AZ(close(v->fds[3])); - AZ(close(v->fds[4])); - for (i = 3; i fds[5] != i) - (void)close(i); - } + for (i = 3; i fds[0])); AZ(close(v->fds[3])); - AZ(close(v->fds[5])); v->fds[0] = v->fds[2]; v->fds[2] = v->fds[3] = -1; VSB_delete(vsb); @@ -399,8 +394,8 @@ varnish_launch(struct varnish *v) memset(fd, 0, sizeof fd); fd[0].fd = v->cli_fd; fd[0].events = POLLIN; - fd[1].fd = v->fds[4]; - fd[1].events = POLLIN|POLLHUP; + fd[1].fd = v->fds[0]; + fd[1].events = POLLHUP; #ifdef __APPLE__ /* * OSX cannot poll a pipe for POLLHUP only, poll just returns @@ -430,7 +425,6 @@ varnish_launch(struct varnish *v) return; } - AZ(close(v->fds[4])); AZ(close(v->cli_fd)); v->cli_fd = nfd; From phk at varnish-cache.org Wed May 2 11:19:06 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Wed, 02 May 2012 13:19:06 +0200 Subject: [master] cb13f32 Convert a lot of testcases which don't care how the response was transferred to examine resp.bodylen instead of resp.http.content-length. Message-ID: commit cb13f327e27a11d6d928692f7c7d56ae4566f98e Author: Poul-Henning Kamp Date: Wed May 2 11:18:05 2012 +0000 Convert a lot of testcases which don't care how the response was transferred to examine resp.bodylen instead of resp.http.content-length. (This is in preparation for streaming being default) diff --git a/bin/varnishtest/tests/b00007.vtc b/bin/varnishtest/tests/b00007.vtc index 58740c6..a07ae9e 100644 --- a/bin/varnishtest/tests/b00007.vtc +++ b/bin/varnishtest/tests/b00007.vtc @@ -26,9 +26,9 @@ client c1 { txreq -url "/bar" rxresp expect resp.status == 200 - expect resp.http.content-length == "4" + expect resp.bodylen == "4" txreq -url "/foo" rxresp expect resp.status == 200 - expect resp.http.content-length == "8" + expect resp.bodylen == "8" } -run diff --git a/bin/varnishtest/tests/b00011.vtc b/bin/varnishtest/tests/b00011.vtc index 9c4e2d3..1e9ee74 100644 --- a/bin/varnishtest/tests/b00011.vtc +++ b/bin/varnishtest/tests/b00011.vtc @@ -16,5 +16,5 @@ client c1 { txreq -url "/" rxresp expect resp.status == 200 - expect resp.http.content-length == 36 + expect resp.bodylen == 36 } -run diff --git a/bin/varnishtest/tests/b00012.vtc b/bin/varnishtest/tests/b00012.vtc index 967ed85..154f6c0 100644 --- a/bin/varnishtest/tests/b00012.vtc +++ b/bin/varnishtest/tests/b00012.vtc @@ -15,15 +15,15 @@ client c1 { send "GET /foo HTTP/1.1\n\nGET /bar HTTP/1.1\n\nGET /bar HTTP/1.1\n\n" rxresp expect resp.status == 200 - expect resp.http.content-length == 3 + expect resp.bodylen == 3 expect resp.http.x-varnish == "1001" rxresp expect resp.status == 200 - expect resp.http.content-length == 6 + expect resp.bodylen == 6 expect resp.http.x-varnish == "1002" rxresp expect resp.status == 200 - expect resp.http.content-length == 6 + expect resp.bodylen == 6 expect resp.http.x-varnish == "1003 1002" } -run diff --git a/bin/varnishtest/tests/b00013.vtc b/bin/varnishtest/tests/b00013.vtc index 8ae90c4..b8e25e6 100644 --- a/bin/varnishtest/tests/b00013.vtc +++ b/bin/varnishtest/tests/b00013.vtc @@ -15,17 +15,17 @@ client c1 { send "GET /foo HTTP/1.1\r\n\r\nGET " rxresp expect resp.status == 200 - expect resp.http.content-length == 3 + expect resp.bodylen == 3 expect resp.http.x-varnish == "1001" send "/bar HTTP/1.1\n\nGET /bar " rxresp expect resp.status == 200 - expect resp.http.content-length == 6 + expect resp.bodylen == 6 expect resp.http.x-varnish == "1002" send "HTTP/1.1\n\n" rxresp expect resp.status == 200 - expect resp.http.content-length == 6 + expect resp.bodylen == 6 expect resp.http.x-varnish == "1003 1002" } -run diff --git a/bin/varnishtest/tests/c00006.vtc b/bin/varnishtest/tests/c00006.vtc index c2c8ec2..9342886 100644 --- a/bin/varnishtest/tests/c00006.vtc +++ b/bin/varnishtest/tests/c00006.vtc @@ -15,7 +15,7 @@ client c1 { txreq -url "/foo" rxresp expect resp.status == 200 - expect resp.http.content-length == 5 + expect resp.bodylen == 5 } client c1 -run @@ -26,7 +26,7 @@ client c1 { txreq -url "/foo" rxresp expect resp.status == 200 - expect resp.http.content-length == 6 + expect resp.bodylen == 6 } client c1 -run diff --git a/bin/varnishtest/tests/c00008.vtc b/bin/varnishtest/tests/c00008.vtc index 3045a5b..69c64d4 100644 --- a/bin/varnishtest/tests/c00008.vtc +++ b/bin/varnishtest/tests/c00008.vtc @@ -15,7 +15,7 @@ client c1 { rxresp expect resp.status == 200 expect resp.http.etag == "foo" - expect resp.http.content-length == 6 + expect resp.bodylen == 6 txreq -url "/foo" \ -hdr "If-Modified-Since: Thu, 26 Jun 2008 12:00:00 GMT" diff --git a/bin/varnishtest/tests/c00009.vtc b/bin/varnishtest/tests/c00009.vtc index 295b092..d0c4b71 100644 --- a/bin/varnishtest/tests/c00009.vtc +++ b/bin/varnishtest/tests/c00009.vtc @@ -32,7 +32,7 @@ client c1 { txreq -url "/foo" rxresp expect resp.status == 200 - expect resp.http.content-length == 6 + expect resp.bodylen == 6 } client c1 -run diff --git a/bin/varnishtest/tests/c00010.vtc b/bin/varnishtest/tests/c00010.vtc index 81ed5b6..6f0aca3 100644 --- a/bin/varnishtest/tests/c00010.vtc +++ b/bin/varnishtest/tests/c00010.vtc @@ -19,12 +19,12 @@ client c1 { txreq -url "/foo" rxresp expect resp.status == 200 - expect resp.http.content-length == 6 + expect resp.bodylen == 6 expect resp.http.x-varnish == "1001" txreq -url "/foo" rxresp expect resp.status == 200 - expect resp.http.content-length == 7 + expect resp.bodylen == 7 expect resp.http.x-varnish == "1002" } diff --git a/bin/varnishtest/tests/c00011.vtc b/bin/varnishtest/tests/c00011.vtc index 18ee757..6bea217 100644 --- a/bin/varnishtest/tests/c00011.vtc +++ b/bin/varnishtest/tests/c00011.vtc @@ -19,12 +19,12 @@ client c1 { txreq -url "/foo" rxresp expect resp.status == 200 - expect resp.http.content-length == 6 + expect resp.bodylen == 6 expect resp.http.x-varnish == "1001" txreq -url "/foo" rxresp expect resp.status == 200 - expect resp.http.content-length == 7 + expect resp.bodylen == 7 expect resp.http.x-varnish == "1002" } diff --git a/bin/varnishtest/tests/c00012.vtc b/bin/varnishtest/tests/c00012.vtc index 24326d8..b578625 100644 --- a/bin/varnishtest/tests/c00012.vtc +++ b/bin/varnishtest/tests/c00012.vtc @@ -19,12 +19,12 @@ client c1 { txreq -url "/foo" rxresp expect resp.status == 200 - expect resp.http.content-length == 6 + expect resp.bodylen == 6 expect resp.http.x-varnish == "1001" txreq -url "/foo" rxresp expect resp.status == 200 - expect resp.http.content-length == 7 + expect resp.bodylen == 7 expect resp.http.x-varnish == "1002" } diff --git a/bin/varnishtest/tests/c00013.vtc b/bin/varnishtest/tests/c00013.vtc index 94c86ca..885be31 100644 --- a/bin/varnishtest/tests/c00013.vtc +++ b/bin/varnishtest/tests/c00013.vtc @@ -16,7 +16,7 @@ client c1 { txreq -url "/foo" -hdr "client: c1" rxresp expect resp.status == 200 - expect resp.http.content-length == 12 + expect resp.bodylen == 12 expect resp.http.x-varnish == "1001" } -start @@ -26,7 +26,7 @@ client c2 { sema r1 sync 2 rxresp expect resp.status == 200 - expect resp.http.content-length == 12 + expect resp.bodylen == 12 expect resp.http.x-varnish == "1002 1001" } -run diff --git a/bin/varnishtest/tests/c00014.vtc b/bin/varnishtest/tests/c00014.vtc index 03089d8..545c469 100644 --- a/bin/varnishtest/tests/c00014.vtc +++ b/bin/varnishtest/tests/c00014.vtc @@ -23,7 +23,7 @@ client c1 { txreq -url "/foo" rxresp expect resp.status == 200 - expect resp.http.content-length == 12 + expect resp.bodylen == 12 expect resp.http.x-varnish == "1001" } -start sema r1 sync 2 @@ -31,7 +31,7 @@ client c2 { txreq -url "/foo" rxresp expect resp.status == 200 - expect resp.http.content-length == 6 + expect resp.bodylen == 6 expect resp.http.x-varnish == "1002" } -run diff --git a/bin/varnishtest/tests/c00015.vtc b/bin/varnishtest/tests/c00015.vtc index 755669b..c323b9c 100644 --- a/bin/varnishtest/tests/c00015.vtc +++ b/bin/varnishtest/tests/c00015.vtc @@ -25,7 +25,7 @@ client c1 { txreq -url "/foo" rxresp expect resp.status == 200 - expect resp.http.content-length == 6 + expect resp.bodylen == 6 expect resp.http.x-varnish == "1001" } -run @@ -35,7 +35,7 @@ client c2 { txreq -url "/foo" rxresp expect resp.status == 200 - expect resp.http.content-length == 7 + expect resp.bodylen == 7 expect resp.http.x-varnish == "1002" } -run @@ -45,7 +45,7 @@ client c3 { txreq -url "/foo" rxresp expect resp.status == 200 - expect resp.http.content-length == 6 + expect resp.bodylen == 6 expect resp.http.x-varnish == "1003 1001" } -run diff --git a/bin/varnishtest/tests/c00025.vtc b/bin/varnishtest/tests/c00025.vtc index 668fdc2..d0cd83d 100644 --- a/bin/varnishtest/tests/c00025.vtc +++ b/bin/varnishtest/tests/c00025.vtc @@ -13,7 +13,7 @@ client c1 { txreq -url "/foo" rxresp expect resp.status == 200 - expect resp.http.content-length == 6 + expect resp.bodylen == 6 txreq -url "/foo" \ -hdr "If-None-Match: 12345678" diff --git a/bin/varnishtest/tests/c00026.vtc b/bin/varnishtest/tests/c00026.vtc index 427efe4..5dcbd41 100644 --- a/bin/varnishtest/tests/c00026.vtc +++ b/bin/varnishtest/tests/c00026.vtc @@ -14,7 +14,7 @@ client c1 { txreq -url "/foo" rxresp expect resp.status == 200 - expect resp.http.content-length == 6 + expect resp.bodylen == 6 txreq -url "/foo" \ -hdr "If-None-Match: 123456789" diff --git a/bin/varnishtest/tests/e00000.vtc b/bin/varnishtest/tests/e00000.vtc index 9aa9f55..1cc41fc 100644 --- a/bin/varnishtest/tests/e00000.vtc +++ b/bin/varnishtest/tests/e00000.vtc @@ -18,7 +18,7 @@ client c1 { txreq rxresp expect resp.status == 200 - expect resp.http.content-length == 33 + expect resp.bodylen == 33 } client c1 -run diff --git a/bin/varnishtest/tests/e00009.vtc b/bin/varnishtest/tests/e00009.vtc index 8a7927d..f3754ff 100644 --- a/bin/varnishtest/tests/e00009.vtc +++ b/bin/varnishtest/tests/e00009.vtc @@ -28,7 +28,6 @@ client c1 { rxresp expect resp.status == 200 expect resp.bodylen == 57 - expect resp.http.content-length == 57 } -run varnish v1 -cli "param.set esi_syntax 1" diff --git a/bin/varnishtest/tests/m00000.vtc b/bin/varnishtest/tests/m00000.vtc index 217668f..7fe2b8c 100644 --- a/bin/varnishtest/tests/m00000.vtc +++ b/bin/varnishtest/tests/m00000.vtc @@ -21,7 +21,7 @@ client c1 { txreq -url "/bar" rxresp expect resp.status == 200 - expect resp.http.content-length == "4" + expect resp.bodylen == "4" expect resp.http.foo == "BAR" expect resp.http.bar == "foo" } -run diff --git a/bin/varnishtest/tests/m00001.vtc b/bin/varnishtest/tests/m00001.vtc index b7ca47f..dd2b064 100644 --- a/bin/varnishtest/tests/m00001.vtc +++ b/bin/varnishtest/tests/m00001.vtc @@ -21,7 +21,7 @@ client c1 { txreq -url "/bar" rxresp expect resp.status == 200 - expect resp.http.content-length == "4" + expect resp.bodylen == "4" expect resp.http.foo == "BAR" expect resp.http.bar == "foo" } -run @@ -33,7 +33,7 @@ client c1 { txreq -url "/bar" rxresp expect resp.status == 200 - expect resp.http.content-length == "4" + expect resp.bodylen == "4" expect resp.http.foo == "bAr" expect resp.http.bar == "fOo" } -run diff --git a/bin/varnishtest/tests/m00003.vtc b/bin/varnishtest/tests/m00003.vtc index 30a0f3c..67d984d 100644 --- a/bin/varnishtest/tests/m00003.vtc +++ b/bin/varnishtest/tests/m00003.vtc @@ -21,7 +21,7 @@ client c1 { txreq -url "/bar" rxresp expect resp.status == 200 - expect resp.http.content-length == "4" + expect resp.bodylen == "4" expect resp.http.foo == "BAR" expect resp.http.bar == "foo" } -run diff --git a/bin/varnishtest/tests/m00004.vtc b/bin/varnishtest/tests/m00004.vtc index 0dbe2cc..232428b 100644 --- a/bin/varnishtest/tests/m00004.vtc +++ b/bin/varnishtest/tests/m00004.vtc @@ -34,21 +34,21 @@ client c1 { txreq -url "/one" rxresp expect resp.status == 200 - expect resp.http.content-length == "4" + expect resp.bodylen == "4" expect resp.http.foo == "bar" expect resp.http.one == "File One" txreq -url "/two" rxresp expect resp.status == 200 - expect resp.http.content-length == "4" + expect resp.bodylen == "4" expect resp.http.foo == "bar" expect resp.http.two == "File Two" txreq -url "/three" rxresp expect resp.status == 200 - expect resp.http.content-length == "4" + expect resp.bodylen == "4" expect resp.http.foo == "bar" expect resp.http.three == "File Three" } -run diff --git a/bin/varnishtest/tests/r00911.vtc b/bin/varnishtest/tests/r00911.vtc index f85556c..5663421 100644 --- a/bin/varnishtest/tests/r00911.vtc +++ b/bin/varnishtest/tests/r00911.vtc @@ -15,6 +15,5 @@ varnish v1 -arg "-p vcc_err_unref=false" -vcl+backend { client c1 { txreq -url /bar rxresp - expect resp.http.content-length == 6 expect resp.bodylen == 6 } -run diff --git a/bin/varnishtest/tests/r00913.vtc b/bin/varnishtest/tests/r00913.vtc index 519436f..e310360 100644 --- a/bin/varnishtest/tests/r00913.vtc +++ b/bin/varnishtest/tests/r00913.vtc @@ -17,6 +17,6 @@ varnish v1 -vcl+backend { client c1 { txreq -url /bar rxresp - expect resp.http.content-length == 6 + expect resp.bodylen == 6 expect resp.http.foo == "XXX" } -run diff --git a/bin/varnishtest/tests/r00917.vtc b/bin/varnishtest/tests/r00917.vtc index 9791034..689d952 100644 --- a/bin/varnishtest/tests/r00917.vtc +++ b/bin/varnishtest/tests/r00917.vtc @@ -11,7 +11,7 @@ varnish v1 -vcl+backend { } -start client c1 { txreq -url /bar rxresp - expect resp.http.content-length == 6 + expect resp.bodylen == 6 } -run varnish v1 -cliok {ban req.url ~ << foo diff --git a/bin/varnishtest/tests/s00000.vtc b/bin/varnishtest/tests/s00000.vtc index 717dd02..bde8934 100644 --- a/bin/varnishtest/tests/s00000.vtc +++ b/bin/varnishtest/tests/s00000.vtc @@ -15,7 +15,7 @@ varnish v1 -vcl+backend { } -start client c1 { txreq -url "/" rxresp - expect resp.http.content-length == 5 + expect resp.bodylen == 5 expect resp.http.x-varnish == "1001" expect resp.status == 200 } -run @@ -27,5 +27,5 @@ client c2 { rxresp expect resp.status == 200 expect resp.http.x-varnish == "1002" - expect resp.http.content-length == 6 + expect resp.bodylen == 6 } -run diff --git a/bin/varnishtest/tests/s00001.vtc b/bin/varnishtest/tests/s00001.vtc index 1dd34bc..68fd520 100644 --- a/bin/varnishtest/tests/s00001.vtc +++ b/bin/varnishtest/tests/s00001.vtc @@ -15,7 +15,7 @@ varnish v1 -vcl+backend { } -start client c1 { txreq -url "/" rxresp - expect resp.http.content-length == 5 + expect resp.bodylen == 5 expect resp.http.x-varnish == "1001" expect resp.status == 200 } -run @@ -28,5 +28,5 @@ client c2 { rxresp expect resp.status == 200 expect resp.http.x-varnish == "1002" - expect resp.http.content-length == 6 + expect resp.bodylen == 6 } -run diff --git a/bin/varnishtest/tests/v00009.vtc b/bin/varnishtest/tests/v00009.vtc index 04b8ccb..5a5d769 100644 --- a/bin/varnishtest/tests/v00009.vtc +++ b/bin/varnishtest/tests/v00009.vtc @@ -39,16 +39,16 @@ client c1 { timeout 3 txreq -url "/foo1" rxresp - expect resp.http.content-length == 1 + expect resp.bodylen == 1 txreq -url "/foo2" rxresp - expect resp.http.content-length == 2 + expect resp.bodylen == 2 txreq -url "/foo3" rxresp - expect resp.http.content-length == 3 + expect resp.bodylen == 3 txreq -url "/foo4" rxresp - expect resp.http.content-length == 4 + expect resp.bodylen == 4 } -run server s1 -start @@ -58,8 +58,8 @@ client c2 { timeout 3 txreq -url "/foo11" rxresp - expect resp.http.content-length == 1 + expect resp.bodylen == 1 txreq -url "/foo22" rxresp - expect resp.http.content-length == 2 + expect resp.bodylen == 2 } -run From phk at varnish-cache.org Wed May 2 19:21:13 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Wed, 02 May 2012 21:21:13 +0200 Subject: [master] b6c079b In the current scheme of things, this can never be the right thing to do. Message-ID: commit b6c079b61034c300fde3951331e2c97731fbed5d Author: Poul-Henning Kamp Date: Wed May 2 19:20:50 2012 +0000 In the current scheme of things, this can never be the right thing to do. diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c index f963bbd..cec3ddb 100644 --- a/bin/varnishd/cache/cache_center.c +++ b/bin/varnishd/cache/cache_center.c @@ -286,7 +286,6 @@ cnt_prepresp(struct sess *sp, struct worker *wrk, struct req *req) break; if (bo != NULL) { AN(bo->do_stream); - VDI_CloseFd(&bo->vbc); HSH_Drop(wrk, &sp->req->obj); VBO_DerefBusyObj(wrk, &bo); } else { From phk at varnish-cache.org Thu May 3 07:43:03 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Thu, 03 May 2012 09:43:03 +0200 Subject: [master] 49a42aa These three tests depend on not running with streaming Message-ID: commit 49a42aa16e7cf1762df69c4709c1ae35bcac969a Author: Poul-Henning Kamp Date: Thu May 3 07:37:50 2012 +0000 These three tests depend on not running with streaming diff --git a/bin/varnishtest/tests/r00702.vtc b/bin/varnishtest/tests/r00702.vtc index a96624e..5075c16 100644 --- a/bin/varnishtest/tests/r00702.vtc +++ b/bin/varnishtest/tests/r00702.vtc @@ -6,6 +6,9 @@ server s1 { } -start varnish v1 -vcl+backend { + sub vcl_fetch { + set beresp.do_stream = false; + } } -start varnish v1 -cliok "param.set http_range_support on" diff --git a/bin/varnishtest/tests/r00704.vtc b/bin/varnishtest/tests/r00704.vtc index 5ee5702..806fc82 100644 --- a/bin/varnishtest/tests/r00704.vtc +++ b/bin/varnishtest/tests/r00704.vtc @@ -6,6 +6,9 @@ server s1 { } -start varnish v1 -vcl+backend { + sub vcl_fetch { + set beresp.do_stream = false; + } } -start varnish v1 -cliok "param.set http_range_support on" diff --git a/bin/varnishtest/tests/r00801.vtc b/bin/varnishtest/tests/r00801.vtc index f6fe5bd..3309f22 100644 --- a/bin/varnishtest/tests/r00801.vtc +++ b/bin/varnishtest/tests/r00801.vtc @@ -11,6 +11,9 @@ server s1 { varnish v1 -vcl+backend { sub vcl_recv { return (pass); } + sub vcl_fetch { + set beresp.do_stream = false; + } } -start client c1 { From phk at varnish-cache.org Thu May 3 08:11:15 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Thu, 03 May 2012 10:11:15 +0200 Subject: [master] 8a22dbf Account for all attempted fetches. Message-ID: commit 8a22dbf5d181eb125ea4652af7317cc41725969a Author: Poul-Henning Kamp Date: Thu May 3 08:10:55 2012 +0000 Account for all attempted fetches. Update some VSC descriptions while at it. diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c index cec3ddb..e343aa8 100644 --- a/bin/varnishd/cache/cache_center.c +++ b/bin/varnishd/cache/cache_center.c @@ -576,6 +576,8 @@ cnt_fetch(struct sess *sp, struct worker *wrk, struct req *req) need_host_hdr = !http_GetHdr(bo->bereq, H_Host, NULL); + wrk->acct_tmp.fetch++; + i = FetchHdr(sp, need_host_hdr, req->objcore == NULL); /* * If we recycle a backend connection, there is a finite chance @@ -902,7 +904,6 @@ cnt_fetchbody(struct sess *sp, struct worker *wrk, struct req *req) HSH_Ref(req->obj->objcore); VBO_DerefBusyObj(wrk, &req->busyobj); - wrk->acct_tmp.fetch++; sp->step = STP_PREPRESP; return (0); } diff --git a/include/tbl/vsc_f_main.h b/include/tbl/vsc_f_main.h index bc79d5b..c3fd288 100644 --- a/include/tbl/vsc_f_main.h +++ b/include/tbl/vsc_f_main.h @@ -147,53 +147,57 @@ VSC_F(backend_retry, uint64_t, 0, 'a', "" ) -VSC_F(fetch_head, uint64_t, 1, 'a', - "Fetch head", - "" +/*--------------------------------------------------------------------- + * Backend fetch statistics + */ + +VSC_F(fetch_head, uint64_t, 1, 'c', + "Fetch no body (HEAD)", + "beresp with no body because the request is HEAD." ) -VSC_F(fetch_length, uint64_t, 1, 'a', +VSC_F(fetch_length, uint64_t, 1, 'c', "Fetch with Length", - "" + "beresp with Content-Length." ) -VSC_F(fetch_chunked, uint64_t, 1, 'a', +VSC_F(fetch_chunked, uint64_t, 1, 'c', "Fetch chunked", - "" + "beresp with Chunked." ) -VSC_F(fetch_eof, uint64_t, 1, 'a', +VSC_F(fetch_eof, uint64_t, 1, 'c', "Fetch EOF", - "" + "beresp with EOF from lack of other info." ) -VSC_F(fetch_bad, uint64_t, 1, 'a', - "Fetch had bad headers", - "" +VSC_F(fetch_bad, uint64_t, 1, 'c', + "Fetch bad T-E", + "beresp failed due to unknown Transfer-Encoding." ) -VSC_F(fetch_close, uint64_t, 1, 'a', +VSC_F(fetch_close, uint64_t, 1, 'c', "Fetch wanted close", - "" + "beresp with EOF due to Connection: Close." ) -VSC_F(fetch_oldhttp, uint64_t, 1, 'a', +VSC_F(fetch_oldhttp, uint64_t, 1, 'c', "Fetch pre HTTP/1.1 closed", - "" -) -VSC_F(fetch_zero, uint64_t, 1, 'a', - "Fetch zero len", - "" + "beresp with EOF due to HTTP < 1.1" ) -VSC_F(fetch_failed, uint64_t, 1, 'a', - "Fetch failed", - "" +VSC_F(fetch_zero, uint64_t, 1, 'c', + "Fetch zero len body", + "beresp with EOF due to keep-live but neither Chunked or Len." ) -VSC_F(fetch_1xx, uint64_t, 1, 'a', +VSC_F(fetch_1xx, uint64_t, 1, 'c', "Fetch no body (1xx)", - "" + "beresp with no body because of 1XX response." ) -VSC_F(fetch_204, uint64_t, 1, 'a', +VSC_F(fetch_204, uint64_t, 1, 'c', "Fetch no body (204)", - "" + "beresp with no body because of 204 response." ) -VSC_F(fetch_304, uint64_t, 1, 'a', +VSC_F(fetch_304, uint64_t, 1, 'c', "Fetch no body (304)", - "" + "beresp with no body because of 304 response." +) +VSC_F(fetch_failed, uint64_t, 1, 'c', + "Fetch body failed", + "beresp body fetch failed." ) /*--------------------------------------------------------------------- From phk at varnish-cache.org Thu May 3 09:34:31 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Thu, 03 May 2012 11:34:31 +0200 Subject: [master] d8094d2 Set streaming by default, to flush out problems. (We don't actually stream yet, we just pretend for some of the way) Message-ID: commit d8094d26a5d5d582f4f0aca8c28227040ebd39cb Author: Poul-Henning Kamp Date: Thu May 3 09:33:35 2012 +0000 Set streaming by default, to flush out problems. (We don't actually stream yet, we just pretend for some of the way) Fix a couple of tests to DTRT accordingly. diff --git a/bin/varnishd/cache/cache_busyobj.c b/bin/varnishd/cache/cache_busyobj.c index 0489734..7fa0291 100644 --- a/bin/varnishd/cache/cache_busyobj.c +++ b/bin/varnishd/cache/cache_busyobj.c @@ -134,6 +134,8 @@ VBO_GetBusyObj(struct worker *wrk) WS_Init(bo->ws, "bo", p, bo->end - p); + bo->do_stream = 1; + return (bo); } diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c index e343aa8..cce170c 100644 --- a/bin/varnishd/cache/cache_center.c +++ b/bin/varnishd/cache/cache_center.c @@ -212,23 +212,15 @@ cnt_prepresp(struct sess *sp, struct worker *wrk, struct req *req) CHECK_OBJ_NOTNULL(req->obj, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(req->vcl, VCL_CONF_MAGIC); - if (bo != NULL) { + if (bo != NULL) CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); - AN(bo->do_stream); - } req->res_mode = 0; if (bo == NULL) req->res_mode |= RES_LEN; - if (bo != NULL && - (bo->h_content_length != NULL || - !bo->do_stream) && - !bo->do_gzip && !bo->do_gunzip) - req->res_mode |= RES_LEN; - - if (!req->disable_esi && req->obj->esidata != NULL) { + if (bo == NULL && !req->disable_esi && req->obj->esidata != NULL) { /* In ESI mode, we don't know the aggregate length */ req->res_mode &= ~RES_LEN; req->res_mode |= RES_ESI; @@ -883,7 +875,8 @@ cnt_fetchbody(struct sess *sp, struct worker *wrk, struct req *req) HSH_Unbusy(&wrk->stats, req->obj->objcore); } - if (Pool_Task(wrk->pool, &bo->fetch_task, POOL_NO_QUEUE)) + if (!bo->do_stream || + Pool_Task(wrk->pool, &bo->fetch_task, POOL_NO_QUEUE)) FetchBody(wrk, bo); while (bo->state < BOS_FAILED) From phk at varnish-cache.org Fri May 4 08:03:09 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Fri, 04 May 2012 10:03:09 +0200 Subject: [master] 31ffe7c Make cnt_prepresp run on incomplete busyobj Message-ID: commit 31ffe7ccab8e4b0b226dbe950f3fbf87e6d16852 Author: Poul-Henning Kamp Date: Fri May 4 08:02:56 2012 +0000 Make cnt_prepresp run on incomplete busyobj diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c index cce170c..a95df05 100644 --- a/bin/varnishd/cache/cache_center.c +++ b/bin/varnishd/cache/cache_center.c @@ -278,8 +278,8 @@ cnt_prepresp(struct sess *sp, struct worker *wrk, struct req *req) break; if (bo != NULL) { AN(bo->do_stream); - HSH_Drop(wrk, &sp->req->obj); - VBO_DerefBusyObj(wrk, &bo); + (void)HSH_Deref(&wrk->stats, NULL, &req->obj); + VBO_DerefBusyObj(wrk, &req->busyobj); } else { (void)HSH_Deref(&wrk->stats, NULL, &req->obj); } @@ -312,10 +312,29 @@ DOT deliver -> DONE [style=bold,color=blue] static int cnt_deliver(struct sess *sp, struct worker *wrk, struct req *req) { + struct busyobj *bo; + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(req, REQ_MAGIC); CHECK_OBJ_NOTNULL(req->obj, OBJECT_MAGIC); + bo = req->busyobj; + CHECK_OBJ_ORNULL(bo, BUSYOBJ_MAGIC); + + if (bo != NULL) { + while (bo->state < BOS_FAILED) + (void)usleep(10000); + assert(bo->state >= BOS_FAILED); + + if (bo->state == BOS_FAILED) { + req->obj = NULL; + VBO_DerefBusyObj(wrk, &req->busyobj); + req->err_code = 503; + sp->step = STP_ERROR; + return (0); + } + VBO_DerefBusyObj(wrk, &req->busyobj); + } AZ(req->busyobj); req->director = NULL; @@ -879,13 +898,13 @@ cnt_fetchbody(struct sess *sp, struct worker *wrk, struct req *req) Pool_Task(wrk->pool, &bo->fetch_task, POOL_NO_QUEUE)) FetchBody(wrk, bo); - while (bo->state < BOS_FAILED) - (void)usleep(10000); - assert(bo->state >= BOS_FAILED); - - assert(WRW_IsReleased(wrk)); + if (req->obj->objcore != NULL) + HSH_Ref(req->obj->objcore); - if (bo->state == BOS_FAILED) { + if (bo->state > BOS_FAILED) { + VBO_DerefBusyObj(wrk, &req->busyobj); + } else if (bo->state == BOS_FAILED) { + /* handle early failures */ req->obj = NULL; VBO_DerefBusyObj(wrk, &req->busyobj); req->err_code = 503; @@ -893,10 +912,7 @@ cnt_fetchbody(struct sess *sp, struct worker *wrk, struct req *req) return (0); } - if (req->obj->objcore != NULL) - HSH_Ref(req->obj->objcore); - - VBO_DerefBusyObj(wrk, &req->busyobj); + assert(WRW_IsReleased(wrk)); sp->step = STP_PREPRESP; return (0); } From phk at varnish-cache.org Fri May 4 10:52:56 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Fri, 04 May 2012 12:52:56 +0200 Subject: [master] a0e3078 Go over prepresp and remove a suboptimal optimization for len=0 objects. Message-ID: commit a0e3078f809d3553b603d5901cce61e70c54415a Author: Poul-Henning Kamp Date: Fri May 4 10:52:28 2012 +0000 Go over prepresp and remove a suboptimal optimization for len=0 objects. diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c index a95df05..332211a 100644 --- a/bin/varnishd/cache/cache_center.c +++ b/bin/varnishd/cache/cache_center.c @@ -184,7 +184,8 @@ cnt_wait(struct sess *sp, struct worker *wrk, struct req *req) } /*-------------------------------------------------------------------- - * We have a refcounted object on the session, now deliver it. + * We have a refcounted object on the session, and possibly the busyobj + * which is fetching it, prepare a response. * DOT subgraph xcluster_prepresp { DOT prepresp [ @@ -212,21 +213,22 @@ cnt_prepresp(struct sess *sp, struct worker *wrk, struct req *req) CHECK_OBJ_NOTNULL(req->obj, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(req->vcl, VCL_CONF_MAGIC); - if (bo != NULL) - CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); - req->res_mode = 0; - if (bo == NULL) - req->res_mode |= RES_LEN; - - if (bo == NULL && !req->disable_esi && req->obj->esidata != NULL) { - /* In ESI mode, we don't know the aggregate length */ - req->res_mode &= ~RES_LEN; - req->res_mode |= RES_ESI; + if (bo == NULL) { + if (!req->disable_esi && req->obj->esidata != NULL) { + /* In ESI mode, we can't know the aggregate length */ + req->res_mode &= ~RES_LEN; + req->res_mode |= RES_ESI; + } else { + req->res_mode |= RES_LEN; + } + } else { + AZ(bo->do_esi); } if (req->esi_level > 0) { + /* Included ESI object, always CHUNKED or EOF */ req->res_mode &= ~RES_LEN; req->res_mode |= RES_ESI_CHILD; } @@ -242,14 +244,8 @@ cnt_prepresp(struct sess *sp, struct worker *wrk, struct req *req) } if (!(req->res_mode & (RES_LEN|RES_CHUNKED|RES_EOF))) { - if (req->obj->len == 0 && - (bo == NULL || !bo->do_stream)) - /* - * If the object is empty, neither ESI nor GUNZIP - * can make it any different size - */ - req->res_mode |= RES_LEN; - else if (!req->wantbody) { + /* We havn't chosen yet, do so */ + if (!req->wantbody) { /* Nothing */ } else if (req->http->protover >= 11) { req->res_mode |= RES_CHUNKED; @@ -901,7 +897,7 @@ cnt_fetchbody(struct sess *sp, struct worker *wrk, struct req *req) if (req->obj->objcore != NULL) HSH_Ref(req->obj->objcore); - if (bo->state > BOS_FAILED) { + if (bo->state == BOS_FINISHED) { VBO_DerefBusyObj(wrk, &req->busyobj); } else if (bo->state == BOS_FAILED) { /* handle early failures */ From kristian at varnish-cache.org Wed May 9 12:59:56 2012 From: kristian at varnish-cache.org (=?UTF-8?Q?Kristian_Lyngst=C3=B8l?=) Date: Wed, 09 May 2012 14:59:56 +0200 Subject: [master] 4805408 Verify range of port numbers before using them Message-ID: commit 48054086d85a912723b59b44d686c4e4d104284e Author: Kristian Lyngstol Date: Wed May 9 14:59:23 2012 +0200 Verify range of port numbers before using them Fixes #1035 diff --git a/bin/varnishtest/tests/r01035.vtc b/bin/varnishtest/tests/r01035.vtc new file mode 100644 index 0000000..ccd6078 --- /dev/null +++ b/bin/varnishtest/tests/r01035.vtc @@ -0,0 +1,8 @@ +varnishtest "Test case for #1035" + +varnish v1 -arg "-a 127.0.0.1:80 -b localhost:8080" +varnish v1 -cliok "param.set listen_address 127.0.0.1:80" +varnish v1 -clierr 106 "param.set listen_address 127.0.0.1:65540" +varnish v1 -clierr 106 "param.set listen_address 127.0.0.1:65536" +varnish v1 -clierr 106 "param.set listen_address 127.0.0.1:-1" +varnish v1 -cliok "param.set listen_address 127.0.0.1:65535" diff --git a/lib/libvarnish/vss.c b/lib/libvarnish/vss.c index 77b8f38..bc0597a 100644 --- a/lib/libvarnish/vss.c +++ b/lib/libvarnish/vss.c @@ -135,6 +135,7 @@ VSS_resolve(const char *addr, const char *port, struct vss_addr ***vap) struct addrinfo hints, *res0, *res; struct vss_addr **va; int i, ret; + long int ptst; char *adp, *hop; *vap = NULL; @@ -148,8 +149,12 @@ VSS_resolve(const char *addr, const char *port, struct vss_addr ***vap) if (adp == NULL) ret = getaddrinfo(addr, port, &hints, &res0); - else + else { + ptst = strtol(adp,NULL,10); + if (ptst < 0 || ptst > 65535) + return(0); ret = getaddrinfo(hop, adp, &hints, &res0); + } free(hop); free(adp); From martin at varnish-cache.org Thu May 10 08:42:54 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Thu, 10 May 2012 10:42:54 +0200 Subject: [master] a9e636e Make the installed headers be nobase. Message-ID: commit a9e636edfbd51d83050d6d458ab99688dbffa908 Author: Martin Blix Grydeland Date: Fri Apr 13 13:41:04 2012 +0200 Make the installed headers be nobase. After the source tree restructure, the header files installed from include/ needs the local directory hierarchy to be left intact. Mark the pkginclude_HEADERS target nobase. diff --git a/include/Makefile.am b/include/Makefile.am index d40169b..91812fa 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,6 +1,6 @@ # -pkginclude_HEADERS = \ +nobase_pkginclude_HEADERS = \ tbl/acct_fields.h \ tbl/backend_poll.h \ tbl/ban_vars.h \ From martin at varnish-cache.org Thu May 10 08:42:54 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Thu, 10 May 2012 10:42:54 +0200 Subject: [master] 0351ac9 Move lib/libvmod_std/vmod.py to lib/libvcl/vmodtool.py Message-ID: commit 0351ac952b100d311d77dd77036c2976e5937661 Author: Martin Blix Grydeland Date: Tue Feb 28 14:41:49 2012 +0100 Move lib/libvmod_std/vmod.py to lib/libvcl/vmodtool.py Move it to a more natural home, as it is not really about libvmod_std, and give it a name that matches it's function (inspired from libtool) diff --git a/lib/libvcl/Makefile.am b/lib/libvcl/Makefile.am index f135e43..ad16981 100644 --- a/lib/libvcl/Makefile.am +++ b/lib/libvcl/Makefile.am @@ -31,7 +31,8 @@ libvcl_la_SOURCES = \ vcc_xref.c EXTRA_DIST = \ - generate.py + generate.py \ + vmodtool.py vcc_obj.c vcc_fixed_token.c vcc_token_defs.h: \ $(srcdir)/generate.py $(top_srcdir)/include/vrt.h diff --git a/lib/libvcl/vmodtool.py b/lib/libvcl/vmodtool.py new file mode 100755 index 0000000..041edcb --- /dev/null +++ b/lib/libvcl/vmodtool.py @@ -0,0 +1,321 @@ +#!/usr/local/bin/python +#- +# Copyright (c) 2010-2011 Varnish Software AS +# All rights reserved. +# +# Author: Poul-Henning Kamp +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# Read the vmod.spec file and produce the vmod.h and vmod.c files. +# +# vmod.h contains the prototypes for the published functions, the module +# C-code should include this file to ensure type-consistency. +# +# vmod.c contains the symbols which VCC and varnishd will use to access +# the module: A structure of properly typed function pointers, the +# size of this structure in bytes, and the definition of the structure +# as a string, suitable for inclusion in the C-source of the compile VCL +# program. + +import sys +import re + +if len(sys.argv) == 2: + specfile = sys.argv[1] +else: + specfile = "vmod.vcc" + +ctypes = { + 'IP': "struct sockaddr_storage *", + 'STRING': "const char *", + 'STRING_LIST': "const char *, ...", + 'BOOL': "unsigned", + 'BACKEND': "struct director *", + 'ENUM': "const char *", + 'TIME': "double", + 'REAL': "double", + 'DURATION': "double", + 'INT': "int", + 'HEADER': "enum gethdr_e, const char *", + 'PRIV_VCL': "struct vmod_priv *", + 'PRIV_CALL': "struct vmod_priv *", + 'VOID': "void", +} + +####################################################################### + +initname = "" +modname = "???" +pstruct = "" +pinit = "" +tdl = "" +plist = "" +slist = "" + +def do_func(fname, rval, args, vargs): + global pstruct + global pinit + global plist + global slist + global tdl + #print(fname, rval, args) + + # C argument list + cargs = "(struct sess *" + for i in args: + cargs += ", " + i + cargs += ")" + + # Prototypes for vmod implementation and interface typedef + proto = ctypes[rval] + " vmod_" + fname + cargs + sproto = ctypes[rval] + " td_" + modname + "_" + fname + cargs + + # append to lists of prototypes + plist += proto + ";\n" + tdl += "typedef " + sproto + ";\n" + + # Append to struct members + pstruct += "\ttd_" + modname + "_" + fname + "\t*" + fname + ";\n" + + # Append to struct initializer + pinit += "\tvmod_" + fname + ",\n" + + # Compose the vmod spec-string + s = modname + '.' + fname + "\\0" + s += "Vmod_Func_" + modname + "." + fname + "\\0" + s += rval + '\\0' + for i in vargs: + s += i + '\\0' + slist += '\t"' + s + '",\n' + +####################################################################### + +def partition(string, separator): + if (hasattr(string,"partition")): + return string.partition(separator) + i = string.find(separator) + if i >= 0: + return (string[:i],separator,string[i+len(separator):]) + return (string, '', '') + +####################################################################### + +def is_c_name(s): + return None != re.match("^[a-z][a-z0-9_]*$", s) + +####################################################################### + +def parse_enum(tq): + assert tq[0] == '{' + assert tq[-1] == '}' + f = tq[1:-1].split(',') + s="ENUM\\0" + b=dict() + for i in f: + i = i.strip() + if not is_c_name(i): + raise Exception("Enum value '%s' is illegal" % i) + if i in b: + raise Exception("Duplicate Enum value '%s'" % i) + b[i] = True + s = s + i.strip() + '\\0' + return s + +####################################################################### + +f = open(specfile, "r") + +def nextline(): + while True: + l0 = f.readline() + if l0 == "": + return l0 + l0 = re.sub("#.*$", "", l0) + l0 = re.sub("\s\s*", " ", l0.strip()) + if l0 != "": + return l0 + +while True: + l0 = nextline() + if l0 == "": + break; + l = partition(l0, " ") + + if l[0] == "Module": + modname = l[2].strip(); + if not is_c_name(modname): + raise Exception("Module name '%s' is illegal" % modname) + continue + + if l[0] == "Init": + initname = l[2].strip(); + if not is_c_name(initname): + raise Exception("Init name '%s' is illegal" % initname) + continue + + if l[0] != "Function": + raise Exception("Expected 'Function' line, got '%s'" % l[0]) + + # Find the return type of the function + l = partition(l[2].strip(), " ") + rt_type = l[0] + if rt_type not in ctypes: + raise Exception("Return type '%s' not a valid type" % rt_type) + + # Find the function name + l = partition(l[2].strip(), "(") + + fname = l[0].strip() + if not is_c_name(fname): + raise Exception("Function name '%s' is illegal" % fname) + + if l[1] != '(': + raise Exception("Missing '('") + + l = l[2] + + while -1 == l.find(")"): + l1 = nextline() + if l1 == "": + raise Exception("End Of Input looking for ')'") + l = l + l1 + + if -1 != l.find("("): + raise Exception("Nesting trouble with '(...)' ") + + if l[-1:] != ')': + raise Exception("Junk after ')'") + + l = l[:-1] + + args = list() + vargs = list() + + for i in re.finditer("([A-Z_]+)\s*({[^}]+})?(,|$)", l): + at = i.group(1) + tq = i.group(2) + if at not in ctypes: + raise Exception( + "Argument type '%s' not a valid type" % at) + + args.append(ctypes[at]) + + if at == "ENUM": + if tq == None: + raise Exception( + "Argument type '%s' needs qualifier {...}" + % at) + at=parse_enum(tq) + + elif tq != None: + raise Exception( + "Argument type '%s' cannot be qualified with {...}" + % at) + + vargs.append(at) + + do_func(fname, rt_type, args, vargs) + +####################################################################### +def dumps(s): + while True: + l = partition(s, "\n") + if len(l[0]) == 0: + break + fc.write('\t"' + l[0] + '\\n"\n') + s = l[2] + +####################################################################### + +if initname != "": + plist += "int " + initname + plist += "(struct vmod_priv *, const struct VCL_conf *);\n" + pstruct += "\tvmod_init_f\t*_init;\n" + pinit += "\t" + initname + ",\n" + slist += '\t"INIT\\0Vmod_Func_' + modname + '._init",\n' + +####################################################################### + +def file_header(fo): + fo.write("""/* + * NB: This file is machine generated, DO NOT EDIT! + * + * Edit vmod.vcc and run vmod.py instead + */ + +""") + +####################################################################### + +fc = open("vcc_if.c", "w") +fh = open("vcc_if.h", "w") + +file_header(fc) +file_header(fh) + +fh.write('struct sess;\n') +fh.write('struct VCL_conf;\n') +fh.write('struct vmod_priv;\n') +fh.write("\n"); + +fh.write(plist) + + +fc.write('#include "config.h"\n') +fc.write('\n') +fc.write('#include "vrt.h"\n') +fc.write('#include "vcc_if.h"\n') +fc.write('#include "vmod_abi.h"\n') +fc.write("\n"); + +fc.write("\n"); + +fc.write(tdl); +fc.write("\n"); + +fc.write('const char Vmod_Name[] = "' + modname + '";\n') + +fc.write("const struct Vmod_Func_" + modname + " {\n") +fc.write(pstruct + "} Vmod_Func = {\n" + pinit + "};\n") +fc.write("\n"); + +fc.write("const int Vmod_Len = sizeof(Vmod_Func);\n") +fc.write("\n"); + +fc.write('const char Vmod_Proto[] =\n') +dumps(tdl); +fc.write('\t"\\n"\n') +dumps("struct Vmod_Func_" + modname + " {\n") +dumps(pstruct + "} Vmod_Func_" + modname + ";\n") +fc.write('\t;\n') +fc.write("\n"); + +fc.write('const char * const Vmod_Spec[] = {\n' + slist + '\t0\n};\n') + +fc.write('const char Vmod_Varnish_ABI[] = VMOD_ABI_Version;\n') + +fh.write('extern const void * const Vmod_Id;\n') +fc.write('const void * const Vmod_Id = &Vmod_Id;\n') + +fc.write("\n") + diff --git a/lib/libvmod_std/Makefile.am b/lib/libvmod_std/Makefile.am index c4128ea..a872837 100644 --- a/lib/libvmod_std/Makefile.am +++ b/lib/libvmod_std/Makefile.am @@ -9,6 +9,7 @@ dist_man_MANS = vmod_std.3 vmoddir = $(pkglibdir)/vmods vmod_srcdir = $(top_srcdir)/lib/libvmod_std +vmodtool = $(top_srcdir)/lib/libvcl/vmodtool.py vmod_LTLIBRARIES = libvmod_std.la libvmod_std_la_LDFLAGS = -module -export-dynamic -avoid-version @@ -20,10 +21,10 @@ libvmod_std_la_SOURCES = \ vmod_std_fileread.c \ vmod_std_conversions.c -vcc_if.c vcc_if.h: $(vmod_srcdir)/vmod.py $(vmod_srcdir)/vmod.vcc - @PYTHON@ $(vmod_srcdir)/vmod.py $(vmod_srcdir)/vmod.vcc +vcc_if.c vcc_if.h: $(vmodtool) $(vmod_srcdir)/vmod.vcc + @PYTHON@ $(vmodtool) $(vmod_srcdir)/vmod.vcc -EXTRA_DIST = vmod.py vmod.vcc +EXTRA_DIST = vmod.vcc CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h diff --git a/lib/libvmod_std/vmod.py b/lib/libvmod_std/vmod.py deleted file mode 100755 index 041edcb..0000000 --- a/lib/libvmod_std/vmod.py +++ /dev/null @@ -1,321 +0,0 @@ -#!/usr/local/bin/python -#- -# Copyright (c) 2010-2011 Varnish Software AS -# All rights reserved. -# -# Author: Poul-Henning Kamp -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# Read the vmod.spec file and produce the vmod.h and vmod.c files. -# -# vmod.h contains the prototypes for the published functions, the module -# C-code should include this file to ensure type-consistency. -# -# vmod.c contains the symbols which VCC and varnishd will use to access -# the module: A structure of properly typed function pointers, the -# size of this structure in bytes, and the definition of the structure -# as a string, suitable for inclusion in the C-source of the compile VCL -# program. - -import sys -import re - -if len(sys.argv) == 2: - specfile = sys.argv[1] -else: - specfile = "vmod.vcc" - -ctypes = { - 'IP': "struct sockaddr_storage *", - 'STRING': "const char *", - 'STRING_LIST': "const char *, ...", - 'BOOL': "unsigned", - 'BACKEND': "struct director *", - 'ENUM': "const char *", - 'TIME': "double", - 'REAL': "double", - 'DURATION': "double", - 'INT': "int", - 'HEADER': "enum gethdr_e, const char *", - 'PRIV_VCL': "struct vmod_priv *", - 'PRIV_CALL': "struct vmod_priv *", - 'VOID': "void", -} - -####################################################################### - -initname = "" -modname = "???" -pstruct = "" -pinit = "" -tdl = "" -plist = "" -slist = "" - -def do_func(fname, rval, args, vargs): - global pstruct - global pinit - global plist - global slist - global tdl - #print(fname, rval, args) - - # C argument list - cargs = "(struct sess *" - for i in args: - cargs += ", " + i - cargs += ")" - - # Prototypes for vmod implementation and interface typedef - proto = ctypes[rval] + " vmod_" + fname + cargs - sproto = ctypes[rval] + " td_" + modname + "_" + fname + cargs - - # append to lists of prototypes - plist += proto + ";\n" - tdl += "typedef " + sproto + ";\n" - - # Append to struct members - pstruct += "\ttd_" + modname + "_" + fname + "\t*" + fname + ";\n" - - # Append to struct initializer - pinit += "\tvmod_" + fname + ",\n" - - # Compose the vmod spec-string - s = modname + '.' + fname + "\\0" - s += "Vmod_Func_" + modname + "." + fname + "\\0" - s += rval + '\\0' - for i in vargs: - s += i + '\\0' - slist += '\t"' + s + '",\n' - -####################################################################### - -def partition(string, separator): - if (hasattr(string,"partition")): - return string.partition(separator) - i = string.find(separator) - if i >= 0: - return (string[:i],separator,string[i+len(separator):]) - return (string, '', '') - -####################################################################### - -def is_c_name(s): - return None != re.match("^[a-z][a-z0-9_]*$", s) - -####################################################################### - -def parse_enum(tq): - assert tq[0] == '{' - assert tq[-1] == '}' - f = tq[1:-1].split(',') - s="ENUM\\0" - b=dict() - for i in f: - i = i.strip() - if not is_c_name(i): - raise Exception("Enum value '%s' is illegal" % i) - if i in b: - raise Exception("Duplicate Enum value '%s'" % i) - b[i] = True - s = s + i.strip() + '\\0' - return s - -####################################################################### - -f = open(specfile, "r") - -def nextline(): - while True: - l0 = f.readline() - if l0 == "": - return l0 - l0 = re.sub("#.*$", "", l0) - l0 = re.sub("\s\s*", " ", l0.strip()) - if l0 != "": - return l0 - -while True: - l0 = nextline() - if l0 == "": - break; - l = partition(l0, " ") - - if l[0] == "Module": - modname = l[2].strip(); - if not is_c_name(modname): - raise Exception("Module name '%s' is illegal" % modname) - continue - - if l[0] == "Init": - initname = l[2].strip(); - if not is_c_name(initname): - raise Exception("Init name '%s' is illegal" % initname) - continue - - if l[0] != "Function": - raise Exception("Expected 'Function' line, got '%s'" % l[0]) - - # Find the return type of the function - l = partition(l[2].strip(), " ") - rt_type = l[0] - if rt_type not in ctypes: - raise Exception("Return type '%s' not a valid type" % rt_type) - - # Find the function name - l = partition(l[2].strip(), "(") - - fname = l[0].strip() - if not is_c_name(fname): - raise Exception("Function name '%s' is illegal" % fname) - - if l[1] != '(': - raise Exception("Missing '('") - - l = l[2] - - while -1 == l.find(")"): - l1 = nextline() - if l1 == "": - raise Exception("End Of Input looking for ')'") - l = l + l1 - - if -1 != l.find("("): - raise Exception("Nesting trouble with '(...)' ") - - if l[-1:] != ')': - raise Exception("Junk after ')'") - - l = l[:-1] - - args = list() - vargs = list() - - for i in re.finditer("([A-Z_]+)\s*({[^}]+})?(,|$)", l): - at = i.group(1) - tq = i.group(2) - if at not in ctypes: - raise Exception( - "Argument type '%s' not a valid type" % at) - - args.append(ctypes[at]) - - if at == "ENUM": - if tq == None: - raise Exception( - "Argument type '%s' needs qualifier {...}" - % at) - at=parse_enum(tq) - - elif tq != None: - raise Exception( - "Argument type '%s' cannot be qualified with {...}" - % at) - - vargs.append(at) - - do_func(fname, rt_type, args, vargs) - -####################################################################### -def dumps(s): - while True: - l = partition(s, "\n") - if len(l[0]) == 0: - break - fc.write('\t"' + l[0] + '\\n"\n') - s = l[2] - -####################################################################### - -if initname != "": - plist += "int " + initname - plist += "(struct vmod_priv *, const struct VCL_conf *);\n" - pstruct += "\tvmod_init_f\t*_init;\n" - pinit += "\t" + initname + ",\n" - slist += '\t"INIT\\0Vmod_Func_' + modname + '._init",\n' - -####################################################################### - -def file_header(fo): - fo.write("""/* - * NB: This file is machine generated, DO NOT EDIT! - * - * Edit vmod.vcc and run vmod.py instead - */ - -""") - -####################################################################### - -fc = open("vcc_if.c", "w") -fh = open("vcc_if.h", "w") - -file_header(fc) -file_header(fh) - -fh.write('struct sess;\n') -fh.write('struct VCL_conf;\n') -fh.write('struct vmod_priv;\n') -fh.write("\n"); - -fh.write(plist) - - -fc.write('#include "config.h"\n') -fc.write('\n') -fc.write('#include "vrt.h"\n') -fc.write('#include "vcc_if.h"\n') -fc.write('#include "vmod_abi.h"\n') -fc.write("\n"); - -fc.write("\n"); - -fc.write(tdl); -fc.write("\n"); - -fc.write('const char Vmod_Name[] = "' + modname + '";\n') - -fc.write("const struct Vmod_Func_" + modname + " {\n") -fc.write(pstruct + "} Vmod_Func = {\n" + pinit + "};\n") -fc.write("\n"); - -fc.write("const int Vmod_Len = sizeof(Vmod_Func);\n") -fc.write("\n"); - -fc.write('const char Vmod_Proto[] =\n') -dumps(tdl); -fc.write('\t"\\n"\n') -dumps("struct Vmod_Func_" + modname + " {\n") -dumps(pstruct + "} Vmod_Func_" + modname + ";\n") -fc.write('\t;\n') -fc.write("\n"); - -fc.write('const char * const Vmod_Spec[] = {\n' + slist + '\t0\n};\n') - -fc.write('const char Vmod_Varnish_ABI[] = VMOD_ABI_Version;\n') - -fh.write('extern const void * const Vmod_Id;\n') -fc.write('const void * const Vmod_Id = &Vmod_Id;\n') - -fc.write("\n") - From martin at varnish-cache.org Thu May 10 08:42:55 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Thu, 10 May 2012 10:42:55 +0200 Subject: [master] d12b924 Install vmodtool.py in pkgdatadir Message-ID: commit d12b924b473e716b71d075ba4c81bc445e30d361 Author: Martin Blix Grydeland Date: Wed Feb 29 10:07:11 2012 +0100 Install vmodtool.py in pkgdatadir diff --git a/lib/libvcl/Makefile.am b/lib/libvcl/Makefile.am index ad16981..02a685f 100644 --- a/lib/libvcl/Makefile.am +++ b/lib/libvcl/Makefile.am @@ -31,7 +31,9 @@ libvcl_la_SOURCES = \ vcc_xref.c EXTRA_DIST = \ - generate.py \ + generate.py + +dist_pkgdata_SCRIPTS = \ vmodtool.py vcc_obj.c vcc_fixed_token.c vcc_token_defs.h: \ From martin at varnish-cache.org Thu May 10 08:42:55 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Thu, 10 May 2012 10:42:55 +0200 Subject: [master] 4d14c2f Install headers needed for vmod compilation in datadir/varnish/include, and export these locations in the pkg_config file. Message-ID: commit 4d14c2f746732f384ff429dcb9f5caedcf247aa8 Author: Martin Blix Grydeland Date: Wed Feb 29 17:39:48 2012 +0100 Install headers needed for vmod compilation in datadir/varnish/include, and export these locations in the pkg_config file. diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am index 8a925b9..bd91dd7 100644 --- a/bin/varnishd/Makefile.am +++ b/bin/varnishd/Makefile.am @@ -84,12 +84,9 @@ varnishd_SOURCES = \ waiter/cache_waiter_ports.c noinst_HEADERS = \ - cache/cache.h \ cache/cache_backend.h \ cache/cache_esi.h \ - common/common.h \ common/heritage.h \ - common/params.h \ default_vcl.h \ hash/hash_slinger.h \ mgt/mgt.h \ @@ -99,6 +96,13 @@ noinst_HEADERS = \ storage/storage_persistent.h \ waiter/waiter.h +# Headers for use with vmods +pkgdataincludedir = $(pkgdatadir)/include +nobase_pkgdatainclude_HEADERS = \ + cache/cache.h \ + common/common.h \ + common/params.h + varnishd_CFLAGS = \ @PCRE_CFLAGS@ \ -DVARNISH_STATE_DIR='"${VARNISH_STATE_DIR}"' \ diff --git a/include/Makefile.am b/include/Makefile.am index 91812fa..3faa540 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,5 +1,6 @@ # +# API headers nobase_pkginclude_HEADERS = \ tbl/acct_fields.h \ tbl/backend_poll.h \ @@ -26,6 +27,7 @@ nobase_pkginclude_HEADERS = \ vapi/vsl_int.h \ vcli.h +# Private headers nobase_noinst_HEADERS = \ binary_heap.h \ compat/daemon.h \ @@ -33,38 +35,42 @@ nobase_noinst_HEADERS = \ compat/srandomdev.h \ flopen.h \ libvcl.h \ - miniobj.h \ persistent.h \ - vas.h \ - vav.h \ - vbm.h \ - vcl.h \ vcli_common.h \ vcli_priv.h \ vcli_serve.h \ vcs_version.h \ - vcs.h \ vct.h \ - vdef.h \ vend.h \ vev.h \ vfil.h \ vin.h \ vlu.h \ vmb.h \ - vmod_abi.h \ vnum.h \ vpf.h \ + vsub.h \ + vss.h \ + vtcp.h \ + vtim.h + +# Headers for use with vmods +pkgdataincludedir = $(pkgdatadir)/include +nobase_pkgdatainclude_HEADERS = \ + miniobj.h \ + vas.h \ + vav.h \ + vbm.h \ + vcl.h \ + vcs.h \ + vmod_abi.h \ vqueue.h \ vre.h \ + vdef.h \ vrt.h \ vrt_obj.h \ vsb.h \ - vsub.h \ - vsha256.h \ - vss.h \ - vtcp.h \ - vtim.h + vsha256.h tbl/vrt_stv_var.h tbl/vcl_returns.h vcl.h vrt_obj.h: $(top_srcdir)/lib/libvcl/generate.py $(top_srcdir)/include/vrt.h mkdir -p tbl diff --git a/varnishapi.pc.in b/varnishapi.pc.in index 71cda56..7f5036a 100644 --- a/varnishapi.pc.in +++ b/varnishapi.pc.in @@ -1,11 +1,18 @@ prefix=@prefix@ exec_prefix=@exec_prefix@ +bindir=@bindir@ +sbindir=@sbindir@ libdir=@libdir@ includedir=@includedir@ -vmoddir=${libdir}/varnish/vmods +pkgincludedir=${includedir}/@PACKAGE@ +datarootdir=@datarootdir@ +datadir=@datadir@ +pkgdatadir=${datadir}/@PACKAGE@ +pkgdataincludedir=${pkgdatadir}/include +vmoddir=${libdir}/@PACKAGE@/vmods Name: VarnishAPI Description: Varnish API Version: @PACKAGE_VERSION@ -Cflags: -I${includedir}/varnish +Cflags: -I${includedir}/@PACKAGE@ Libs: -L${libdir} -lvarnishapi From martin at varnish-cache.org Thu May 10 08:42:55 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Thu, 10 May 2012 10:42:55 +0200 Subject: [master] 7bf7038 Add a varnishapi-uninstalled.pc file, for use by out-of-tree vmod building against an uninstalled Varnish build tree. Message-ID: commit 7bf7038f4e577320b4c8e19fee89f3ef18c03725 Author: Martin Blix Grydeland Date: Fri Apr 13 13:39:01 2012 +0200 Add a varnishapi-uninstalled.pc file, for use by out-of-tree vmod building against an uninstalled Varnish build tree. diff --git a/configure.ac b/configure.ac index e6ecfb9..20134a7 100644 --- a/configure.ac +++ b/configure.ac @@ -554,5 +554,6 @@ AC_CONFIG_FILES([ man/Makefile redhat/Makefile varnishapi.pc + varnishapi-uninstalled.pc ]) AC_OUTPUT diff --git a/varnishapi-uninstalled.pc.in b/varnishapi-uninstalled.pc.in new file mode 100644 index 0000000..3a8f744 --- /dev/null +++ b/varnishapi-uninstalled.pc.in @@ -0,0 +1,20 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +bindir=@bindir@ +sbindir=@sbindir@ +libdir=@libdir@ +includedir=@includedir@ +pkgincludedir=${includedir}/@PACKAGE@ +datarootdir=@datarootdir@ +datadir=@datadir@ +pkgdatadir=${datadir}/@PACKAGE@ +pkgdataincludedir=${pkgdatadir}/include +vmoddir=${libdir}/@PACKAGE@/vmods +builddir=@abs_top_builddir@ +srcdir=@abs_top_srcdir@ + +Name: VarnishAPI +Description: Varnish API +Version: @PACKAGE_VERSION@ +Cflags: -I${includedir}/@PACKAGE@ +Libs: -L${libdir} -lvarnishapi From phk at varnish-cache.org Thu May 10 08:57:58 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Thu, 10 May 2012 10:57:58 +0200 Subject: [master] 40ee205 These are not debug commands. Message-ID: commit 40ee205a3c8c6a95db08116ff7f4d7f51f7abbc9 Author: Poul-Henning Kamp Date: Thu May 10 08:57:47 2012 +0000 These are not debug commands. diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c index c2d022d..45b85d0 100644 --- a/bin/varnishd/cache/cache_backend_cfg.c +++ b/bin/varnishd/cache/cache_backend_cfg.c @@ -487,9 +487,9 @@ cli_backend_set_health(struct cli *cli, const char * const *av, void *priv) static struct cli_proto backend_cmds[] = { { "backend.list", "backend.list", - "\tList all backends\n", 0, 1, "d", cli_backend_list }, + "\tList all backends\n", 0, 1, "", cli_backend_list }, { "backend.set_health", "backend.set_health matcher state", - "\tShow a backend\n", 2, 2, "d", cli_backend_set_health }, + "\tShow a backend\n", 2, 2, "", cli_backend_set_health }, { NULL } }; From daghf at varnish-cache.org Thu May 10 08:59:18 2012 From: daghf at varnish-cache.org (Dag Haavi Finstad) Date: Thu, 10 May 2012 10:59:18 +0200 Subject: [master] 4020b13 Req.hash_always_miss now implies req.hash_ignore_busy. Message-ID: commit 4020b13d0eab47df865d3b055404ed84b8ffd459 Author: Dag Haavi Finstad Date: Tue May 8 17:10:58 2012 +0200 Req.hash_always_miss now implies req.hash_ignore_busy. Fixes a case where we might get a cache hit even though hash_always_miss is set. Fixes: #1073 diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c index 6facf0a..1228126 100644 --- a/bin/varnishd/cache/cache_hash.c +++ b/bin/varnishd/cache/cache_hash.c @@ -332,7 +332,7 @@ HSH_Lookup(struct sess *sp) if (oc->flags & OC_F_BUSY || oc->busyobj != NULL) { CHECK_OBJ_ORNULL(oc->busyobj, BUSYOBJ_MAGIC); - if (req->hash_ignore_busy) + if (req->hash_ignore_busy || req->hash_always_miss) continue; if (oc->busyobj != NULL && diff --git a/bin/varnishtest/tests/r01073.vtc b/bin/varnishtest/tests/r01073.vtc new file mode 100644 index 0000000..936f8ce --- /dev/null +++ b/bin/varnishtest/tests/r01073.vtc @@ -0,0 +1,55 @@ +varnishtest "Test that hash_always_miss also implies hash_ignore_busy. Ticket #1073." + +server s1 { + rxreq + sema r1 sync 2 + sema r2 sync 2 + delay 1 + txresp -hdr "Server: 1" +} -start + +server s2 { + rxreq + sema r2 sync 2 + txresp -hdr "Server: 2" +} -start + +varnish v1 -vcl+backend { + sub vcl_recv { + if (req.http.x-hash-always-miss == "1") { + set req.hash_always_miss = true; + } + if (req.http.x-client == "1") { + set req.backend = s1; + } + if (req.http.x-client == "2") { + set req.backend = s2; + } + } + sub vcl_deliver { + if(obj.hits > 0) { + set resp.http.X-Cache = "HIT"; + } else { + set resp.http.X-Cache = "MISS"; + } + } +} -start + +client c1 { + txreq -url "/" -hdr "x-client: 1" + rxresp + expect resp.status == 200 + expect resp.http.Server == "1" +} -start + +client c2 { + sema r1 sync 2 + txreq -url "/" -hdr "x-client: 2" -hdr "x-hash-always-miss: 1" + txreq -url "/" -hdr "x-client: 2" + rxresp + expect resp.status == 200 + expect resp.http.Server == "2" +} -start + +client c1 -wait +client c2 -wait From phk at varnish-cache.org Thu May 10 09:10:06 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Thu, 10 May 2012 11:10:06 +0200 Subject: [master] 3814b12 Use admin health to control test-state Message-ID: commit 3814b12840885117f3b2f78de7f5bc25f99fd405 Author: Poul-Henning Kamp Date: Thu May 10 09:09:49 2012 +0000 Use admin health to control test-state diff --git a/bin/varnishtest/tests/r00306.vtc b/bin/varnishtest/tests/r00306.vtc index ebc1774..079e994 100644 --- a/bin/varnishtest/tests/r00306.vtc +++ b/bin/varnishtest/tests/r00306.vtc @@ -23,10 +23,6 @@ varnish v1 -vcl { } backend s2 { .host = "${s2_addr}"; .port = "${s2_port}"; - .probe = { - .url = "/"; - .initial = 0; - } } director foo random { { .backend = s2; .weight = 1; } @@ -38,6 +34,9 @@ varnish v1 -vcl { } } -start +varnish v1 -cliok "backend.set_health s2 sick" +varnish v1 -cliok "backend.list" + client c1 { timeout 10 From phk at varnish-cache.org Thu May 10 09:24:52 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Thu, 10 May 2012 11:24:52 +0200 Subject: [master] 0352ea2 Make the random/hash/client director use a stable hash. Message-ID: commit 0352ea2567c5b4df803635ec8ac4288ae5c0fa07 Author: Poul-Henning Kamp Date: Thu May 10 09:20:54 2012 +0000 Make the random/hash/client director use a stable hash. If the chosen backend is sick or fails to give us a connection, we rescale the keys position in the backends window onto the all the remaining backends. The upside of this is that we get a stable and predicatable hash distribution. The downside of this is that you are very unlikely to spot the healthy .weight=1 backend between two .weight=100 sick ones before your retries run out. Inspired by: patch from WaveCDN diff --git a/bin/varnishd/cache/cache_dir_random.c b/bin/varnishd/cache/cache_dir_random.c index b323343..8a0bcd2 100644 --- a/bin/varnishd/cache/cache_dir_random.c +++ b/bin/varnishd/cache/cache_dir_random.c @@ -127,32 +127,50 @@ vdi_random_init_seed(const struct vdi_random *vs, const struct sess *sp) * Find the healthy backend corresponding to the weight r [0...1[ */ static struct vbc * -vdi_random_pick_one(struct sess *sp, const struct vdi_random *vs, double r) +vdi_random_pick_one(struct sess *sp, const struct vdi_random *vs, double r, + int retries) { double w[vs->nhosts]; int i; - double s1; - - assert(r >= 0.0 && r < 1.0); + double s1, s2; + struct vbc *vbc; + /* Sum up the weights of all backends */ memset(w, 0, sizeof w); - /* Sum up the weights of healty backends */ s1 = 0.0; for (i = 0; i < vs->nhosts; i++) { - if (VDI_Healthy(vs->hosts[i].backend, sp)) - w[i] = vs->hosts[i].weight; + w[i] = vs->hosts[i].weight; s1 += w[i]; } - if (s1 == 0.0) return (NULL); - r *= s1; - s1 = 0.0; - for (i = 0; i < vs->nhosts; i++) { - s1 += w[i]; - if (r < s1) - return(VDI_GetFd(vs->hosts[i].backend, sp)); + while (retries-- > 0) { + assert(r >= 0.0 && r < 1.0); + + r *= s1; + s2 = 0.0; + for (i = 0; i < vs->nhosts; i++) { + s2 += w[i]; + if (r >= s2) + continue; + if (!VDI_Healthy(vs->hosts[i].backend, sp)) + break; + vbc = VDI_GetFd(vs->hosts[i].backend, sp); + if (vbc == NULL) + break; + return (vbc); + } + /* + * Rescale and rotate r's relative position this backends + * window onto the remaining backends and try again. + */ + r -= (s2 - w[i]); // r in [0...w[i][ + r /= w[i]; // r in [0...1[ + r *= (s1 - w[i])/s1; // r in [0...1-W[i]] + r += s2 / s1; // rotate + if (r >= 1.0) + r -= 1.0; } return (NULL); } @@ -165,10 +183,8 @@ vdi_random_pick_one(struct sess *sp, const struct vdi_random *vs, double r) static struct vbc * vdi_random_getfd(const struct director *d, struct sess *sp) { - int k; struct vdi_random *vs; double r; - struct vbc *vbe; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC); @@ -176,17 +192,12 @@ vdi_random_getfd(const struct director *d, struct sess *sp) r = vdi_random_init_seed(vs, sp); - for (k = 0; k < vs->retries; k++) { - vbe = vdi_random_pick_one(sp, vs, r); - if (vbe != NULL) - return (vbe); - r = vdi_random_sha((void *)&r, sizeof(r)); - } - return (NULL); + return (vdi_random_pick_one(sp, vs, r, vs->retries)); } /* * Healthy if just a single backend is... + * XXX: we should really have a weight param/criteria here */ static unsigned vdi_random_healthy(const struct director *d, const struct sess *sp) From martin at varnish-cache.org Thu May 10 09:50:45 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Thu, 10 May 2012 11:50:45 +0200 Subject: [master] 9d0e486 Don't consider a vcc expr to be constant after vcc_expr_tostring. Message-ID: commit 9d0e486fe21199e6c059eb829f5d666611806012 Author: Martin Blix Grydeland Date: Tue May 8 14:20:42 2012 +0200 Don't consider a vcc expr to be constant after vcc_expr_tostring. Avoids vcc errors from constructs like "std.log("Test: " + 1);" Fixes: #1134 diff --git a/bin/varnishtest/tests/r01134.vtc b/bin/varnishtest/tests/r01134.vtc new file mode 100644 index 0000000..73f4e36 --- /dev/null +++ b/bin/varnishtest/tests/r01134.vtc @@ -0,0 +1,19 @@ +varnishtest "vcc const/non-const tostring conversion - bug 1134" + +server s1 { + rxreq + txresp +} -start + +varnish v1 -vcl+backend { + sub vcl_recv { + set req.http.x-test = "Test " + 1; + } +} -start + +client c1 { + txreq + rxresp + expect resp.status == 200 +} -run + diff --git a/lib/libvcl/vcc_expr.c b/lib/libvcl/vcc_expr.c index 30e63d9..19a455c 100644 --- a/lib/libvcl/vcc_expr.c +++ b/lib/libvcl/vcc_expr.c @@ -434,8 +434,10 @@ vcc_expr_tostring(struct expr **e, enum var_type fmt) case TIME: p = "VRT_time_string(sp, \v1)"; break; default: break; } - if (p != NULL) + if (p != NULL) { *e = vcc_expr_edit(fmt, p, *e, NULL); + (*e)->constant = 0; + } } /*-------------------------------------------------------------------- From martin at varnish-cache.org Thu May 10 09:50:45 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Thu, 10 May 2012 11:50:45 +0200 Subject: [master] 5b3e41b Fix vmod_log (VRT_StringList returns end of string, not beginning) Message-ID: commit 5b3e41b4958ea33012ef290c706e6c45d540d361 Author: Martin Blix Grydeland Date: Tue Apr 24 14:21:42 2012 +0200 Fix vmod_log (VRT_StringList returns end of string, not beginning) Fixes: #1135 diff --git a/lib/libvmod_std/vmod_std.c b/lib/libvmod_std/vmod_std.c index 5b5c0aa..8ae9ec1 100644 --- a/lib/libvmod_std/vmod_std.c +++ b/lib/libvmod_std/vmod_std.c @@ -147,19 +147,18 @@ vmod_random(struct sess *sp, double lo, double hi) void __match_proto__() vmod_log(struct sess *sp, const char *fmt, ...) { - char *p; unsigned u; va_list ap; txt t; u = WS_Reserve(sp->req->ws, 0); - p = sp->req->ws->f; + t.b = sp->req->ws->f; va_start(ap, fmt); - p = VRT_StringList(p, u, fmt, ap); + t.e = VRT_StringList(t.b, u, fmt, ap); va_end(ap); - if (p != NULL) { - t.b = p; - t.e = strchr(p, '\0'); + if (t.e != NULL) { + assert(t.e > t.b); + t.e--; VSLbt(sp->req->vsl, SLT_VCL_Log, t); } WS_Release(sp->req->ws, 0); From phk at varnish-cache.org Thu May 10 09:56:52 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Thu, 10 May 2012 11:56:52 +0200 Subject: [master] 390fa49 Merge branch 'master' of ssh://git.varnish-cache.org/git/varnish-cache Message-ID: commit 390fa49f574a3f8e44a6f30c508641e513c7b737 Merge: 9efa2b0 5b3e41b Author: Poul-Henning Kamp Date: Thu May 10 09:56:49 2012 +0000 Merge branch 'master' of ssh://git.varnish-cache.org/git/varnish-cache From phk at varnish-cache.org Thu May 10 09:56:52 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Thu, 10 May 2012 11:56:52 +0200 Subject: [master] 9efa2b0 Introduce the obj_readonly parameter which disables obj.hits and obj.lastuse in order to not dirty VM pages containing cached objects. Message-ID: commit 9efa2b0005a9e9fbfee7ba47018ee64df679594f Author: Poul-Henning Kamp Date: Thu May 10 09:56:07 2012 +0000 Introduce the obj_readonly parameter which disables obj.hits and obj.lastuse in order to not dirty VM pages containing cached objects. diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c index 332211a..c028cb5 100644 --- a/bin/varnishd/cache/cache_center.c +++ b/bin/varnishd/cache/cache_center.c @@ -261,7 +261,8 @@ cnt_prepresp(struct sess *sp, struct worker *wrk, struct req *req) cache_param->lru_timeout && EXP_Touch(req->obj->objcore)) req->obj->last_lru = req->t_resp; - req->obj->last_use = req->t_resp; /* XXX: locking ? */ + if (!cache_param->obj_readonly) + req->obj->last_use = req->t_resp; /* XXX: locking ? */ } HTTP_Setup(req->resp, req->ws, req->vsl, HTTP_Resp); RES_BuildHttp(sp); diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c index 1228126..6b84bab 100644 --- a/bin/varnishd/cache/cache_hash.c +++ b/bin/varnishd/cache/cache_hash.c @@ -398,7 +398,7 @@ HSH_Lookup(struct sess *sp) assert(hash->deref(oh)); o = oc_getobj(&wrk->stats, oc); CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); - if (o->hits < INT_MAX) + if (!cache_param->obj_readonly && o->hits < INT_MAX) o->hits++; return (oc); } diff --git a/bin/varnishd/common/params.h b/bin/varnishd/common/params.h index 6e502fd..1e13657 100644 --- a/bin/varnishd/common/params.h +++ b/bin/varnishd/common/params.h @@ -188,6 +188,8 @@ struct params { unsigned gzip_window; unsigned gzip_memlevel; + unsigned obj_readonly; + double critbit_cooloff; double shortlived; diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c index 885d2ce..c8f62bb 100644 --- a/bin/varnishd/mgt/mgt_param.c +++ b/bin/varnishd/mgt/mgt_param.c @@ -1260,6 +1260,12 @@ static const struct parspec input_parspec[] = { 0, "10,100,10", ""}, + { "obj_readonly", tweak_bool, &mgt_param.obj_readonly, 0, 0, + "If set, we do not update obj.hits and obj.lastuse to" + "avoid dirtying VM pages associated with cached objects.", + 0, + "false", ""}, + { NULL, NULL, NULL } }; From phk at varnish-cache.org Mon May 14 10:06:33 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Mon, 14 May 2012 12:06:33 +0200 Subject: [master] f289def Make all objects have an objcore, even for the vcl_recv->pass case. Message-ID: commit f289def3a62bdc15aa0ef78217254edba689ef2f Author: Poul-Henning Kamp Date: Mon May 14 10:05:53 2012 +0000 Make all objects have an objcore, even for the vcl_recv->pass case. This simplifies some nasty corner cases. diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c index c53d945..6986d21 100644 --- a/bin/varnishd/cache/cache_ban.c +++ b/bin/varnishd/cache/cache_ban.c @@ -447,6 +447,7 @@ BAN_NewObjCore(struct objcore *oc) CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); AZ(oc->ban); + AN(oc->objhead); Lck_Lock(&ban_mtx); oc->ban = ban_start; ban_start->refcount++; diff --git a/bin/varnishd/cache/cache_busyobj.c b/bin/varnishd/cache/cache_busyobj.c index 7fa0291..48efe08 100644 --- a/bin/varnishd/cache/cache_busyobj.c +++ b/bin/varnishd/cache/cache_busyobj.c @@ -152,7 +152,7 @@ VBO_DerefBusyObj(struct worker *wrk, struct busyobj **pbo) *pbo = NULL; CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); CHECK_OBJ_ORNULL(bo->fetch_obj, OBJECT_MAGIC); - if (bo->fetch_obj != NULL && bo->fetch_obj->objcore != NULL) { + if (bo->fetch_obj != NULL && bo->fetch_obj->objcore->objhead != NULL) { oc = bo->fetch_obj->objcore; CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); CHECK_OBJ_NOTNULL(oc->objhead, OBJHEAD_MAGIC); diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c index c028cb5..9b7a968 100644 --- a/bin/varnishd/cache/cache_center.c +++ b/bin/varnishd/cache/cache_center.c @@ -256,7 +256,7 @@ cnt_prepresp(struct sess *sp, struct worker *wrk, struct req *req) } req->t_resp = W_TIM_real(wrk); - if (req->obj->objcore != NULL) { + if (req->obj->objcore->objhead != NULL) { if ((req->t_resp - req->obj->last_lru) > cache_param->lru_timeout && EXP_Touch(req->obj->objcore)) @@ -340,11 +340,8 @@ cnt_deliver(struct sess *sp, struct worker *wrk, struct req *req) RES_WriteObj(sp); /* No point in saving the body if it is hit-for-pass */ - if (req->obj->objcore != NULL) { - CHECK_OBJ_NOTNULL(req->obj->objcore, OBJCORE_MAGIC); - if (req->obj->objcore->flags & OC_F_PASS) - STV_Freestore(req->obj); - } + if (req->obj->objcore->flags & OC_F_PASS) + STV_Freestore(req->obj); assert(WRW_IsReleased(wrk)); (void)HSH_Deref(&wrk->stats, NULL, &req->obj); @@ -492,6 +489,7 @@ cnt_error(struct sess *sp, struct worker *wrk, struct req *req) bo->vsl->wid = sp->vsl_id; AZ(bo->stats); bo->stats = &wrk->stats; + req->objcore = HSH_NewObjCore(wrk); req->obj = STV_NewObject(bo, &req->objcore, TRANSIENT_STORAGE, cache_param->http_resp_size, (uint16_t)cache_param->http_max_hdr); @@ -586,7 +584,7 @@ cnt_fetch(struct sess *sp, struct worker *wrk, struct req *req) wrk->acct_tmp.fetch++; - i = FetchHdr(sp, need_host_hdr, req->objcore == NULL); + i = FetchHdr(sp, need_host_hdr, req->objcore->objhead == NULL); /* * If we recycle a backend connection, there is a finite chance * that the backend closed it before we get a request to it. @@ -594,7 +592,7 @@ cnt_fetch(struct sess *sp, struct worker *wrk, struct req *req) */ if (i == 1) { VSC_C_main->backend_retry++; - i = FetchHdr(sp, need_host_hdr, req->objcore == NULL); + i = FetchHdr(sp, need_host_hdr, req->objcore->objhead == NULL); } if (i) { @@ -626,7 +624,7 @@ cnt_fetch(struct sess *sp, struct worker *wrk, struct req *req) RFC2616_Ttl(bo, sp->req->xid); /* pass from vclrecv{} has negative TTL */ - if (req->objcore == NULL) + if (req->objcore->objhead == NULL) bo->exp.ttl = -1.; AZ(bo->do_esi); @@ -634,7 +632,7 @@ cnt_fetch(struct sess *sp, struct worker *wrk, struct req *req) VCL_fetch_method(sp); - if (req->objcore != NULL && bo->do_pass) + if (bo->do_pass) req->objcore->flags |= OC_F_PASS; switch (req->handling) { @@ -652,7 +650,7 @@ cnt_fetch(struct sess *sp, struct worker *wrk, struct req *req) /* Clean up partial fetch */ AZ(bo->vbc); - if (req->objcore != NULL) { + if (req->objcore->objhead != NULL || req->handling == VCL_RET_ERROR) { CHECK_OBJ_NOTNULL(req->objcore, OBJCORE_MAGIC); AZ(HSH_Deref(&wrk->stats, req->objcore, NULL)); req->objcore = NULL; @@ -707,7 +705,7 @@ cnt_fetchbody(struct sess *sp, struct worker *wrk, struct req *req) assert(req->handling == VCL_RET_DELIVER); - if (req->objcore == NULL) { + if (req->objcore->objhead == NULL) { /* This is a pass from vcl_recv */ pass = 1; /* VCL may have fiddled this, but that doesn't help */ @@ -785,7 +783,7 @@ cnt_fetchbody(struct sess *sp, struct worker *wrk, struct req *req) pass ? HTTPH_R_PASS : HTTPH_A_INS, &nhttp); /* Create Vary instructions */ - if (req->objcore != NULL) { + if (req->objcore->objhead != NULL) { CHECK_OBJ_NOTNULL(req->objcore, OBJCORE_MAGIC); vary = VRY_Create(req, bo->beresp); if (vary != NULL) { @@ -884,7 +882,7 @@ cnt_fetchbody(struct sess *sp, struct worker *wrk, struct req *req) assert(bo->refcount == 2); /* one for each thread */ - if (req->obj->objcore != NULL) { + if (req->obj->objcore->objhead != NULL) { EXP_Insert(req->obj); AN(req->obj->objcore->ban); AZ(req->obj->ws_o->overflow); @@ -895,7 +893,7 @@ cnt_fetchbody(struct sess *sp, struct worker *wrk, struct req *req) Pool_Task(wrk->pool, &bo->fetch_task, POOL_NO_QUEUE)) FetchBody(wrk, bo); - if (req->obj->objcore != NULL) + if (req->obj->objcore->objhead != NULL) HSH_Ref(req->obj->objcore); if (bo->state == BOS_FINISHED) { @@ -1249,6 +1247,9 @@ cnt_pass(struct sess *sp, struct worker *wrk, struct req *req) assert(req->handling == VCL_RET_PASS); wrk->acct_tmp.pass++; sp->step = STP_FETCH; + + req->objcore = HSH_NewObjCore(wrk); + req->objcore->busyobj = bo; return (0); } diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c index ee9147d..7e9a25c 100644 --- a/bin/varnishd/cache/cache_fetch.c +++ b/bin/varnishd/cache/cache_fetch.c @@ -453,10 +453,8 @@ FetchHdr(struct sess *sp, int need_host_hdr, int sendbody) AN(req->director); AZ(req->obj); - if (req->objcore != NULL) { /* pass has no objcore */ - CHECK_OBJ_NOTNULL(req->objcore, OBJCORE_MAGIC); - AN(req->objcore->flags & OC_F_BUSY); - } + CHECK_OBJ_NOTNULL(req->objcore, OBJCORE_MAGIC); + AN(req->objcore->flags & OC_F_BUSY); hp = bo->bereq; @@ -687,7 +685,7 @@ FetchBody(struct worker *wrk, void *priv) /* XXX: Atomic assignment, needs volatile/membar ? */ bo->state = BOS_FINISHED; } - if (obj->objcore != NULL) + if (obj->objcore->objhead != NULL) HSH_Complete(obj->objcore); bo->stats = NULL; VBO_DerefBusyObj(wrk, &bo); diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c index 6b84bab..bc94352 100644 --- a/bin/varnishd/cache/cache_hash.c +++ b/bin/varnishd/cache/cache_hash.c @@ -66,23 +66,31 @@ static const struct hash_slinger *hash; /*---------------------------------------------------------------------*/ + +struct objcore * +HSH_NewObjCore(struct worker *wrk) +{ + struct objcore *oc; + + ALLOC_OBJ(oc, OBJCORE_MAGIC); + XXXAN(oc); + wrk->stats.n_objectcore++; + oc->flags |= OC_F_BUSY; + return (oc); +} + +/*---------------------------------------------------------------------*/ /* Precreate an objhead and object for later use */ static void hsh_prealloc(struct worker *wrk) { struct objhead *oh; - struct objcore *oc; struct waitinglist *wl; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); - if (wrk->nobjcore == NULL) { - ALLOC_OBJ(oc, OBJCORE_MAGIC); - XXXAN(oc); - wrk->nobjcore = oc; - wrk->stats.n_objectcore++; - oc->flags |= OC_F_BUSY; - } + if (wrk->nobjcore == NULL) + wrk->nobjcore = HSH_NewObjCore(wrk); CHECK_OBJ_NOTNULL(wrk->nobjcore, OBJCORE_MAGIC); if (wrk->nobjhead == NULL) { @@ -663,40 +671,31 @@ HSH_Deref(struct dstat *ds, struct objcore *oc, struct object **oo) oc = o->objcore; } - if (o != NULL && oc == NULL) { - /* - * A pass object with neither objcore nor objhdr reference. - * -> simply free the (Transient) storage - */ - STV_Freestore(o); - STV_free(o->objstore); - ds->n_object--; - return (0); - } - CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); oh = oc->objhead; - CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); + if (oh != NULL) { + CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); - Lck_Lock(&oh->mtx); - assert(oh->refcnt > 0); - assert(oc->refcnt > 0); - r = --oc->refcnt; - if (!r) - VTAILQ_REMOVE(&oh->objcs, oc, list); - else { - /* Must have an object */ - AN(oc->methods); - } - if (oh->waitinglist != NULL) - hsh_rush(ds, oh); - Lck_Unlock(&oh->mtx); - if (r != 0) - return (r); + Lck_Lock(&oh->mtx); + assert(oh->refcnt > 0); + assert(oc->refcnt > 0); + r = --oc->refcnt; + if (!r) + VTAILQ_REMOVE(&oh->objcs, oc, list); + else { + /* Must have an object */ + AN(oc->methods); + } + if (oh->waitinglist != NULL) + hsh_rush(ds, oh); + Lck_Unlock(&oh->mtx); + if (r != 0) + return (r); - BAN_DestroyObj(oc); - AZ(oc->ban); + BAN_DestroyObj(oc); + AZ(oc->ban); + } if (oc->methods != NULL) { oc_freeobj(oc); @@ -705,11 +704,13 @@ HSH_Deref(struct dstat *ds, struct objcore *oc, struct object **oo) FREE_OBJ(oc); ds->n_objectcore--; - /* Drop our ref on the objhead */ - assert(oh->refcnt > 0); - if (hash->deref(oh)) - return (0); - HSH_DeleteObjHead(ds, oh); + if (oh != NULL) { + /* Drop our ref on the objhead */ + assert(oh->refcnt > 0); + if (hash->deref(oh)) + return (0); + HSH_DeleteObjHead(ds, oh); + } return (0); } diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c index 2e56666..37fb7a0 100644 --- a/bin/varnishd/cache/cache_vrt_var.c +++ b/bin/varnishd/cache/cache_vrt_var.c @@ -141,7 +141,7 @@ VRT_l_beresp_saintmode(const struct sess *sp, double a) if (!vbc->backend) return; CHECK_OBJ_NOTNULL(vbc->backend, BACKEND_MAGIC); - if (!sp->req->objcore) + if (!sp->req->objcore->objhead) return; CHECK_OBJ_NOTNULL(sp->req->objcore, OBJCORE_MAGIC); diff --git a/bin/varnishd/hash/hash_slinger.h b/bin/varnishd/hash/hash_slinger.h index 17d67f9..cbf62ba 100644 --- a/bin/varnishd/hash/hash_slinger.h +++ b/bin/varnishd/hash/hash_slinger.h @@ -60,6 +60,7 @@ void HSH_AddString(const struct sess *sp, const char *str); void HSH_Insert(struct worker *, const void *hash, struct objcore *); void HSH_Purge(const struct sess *, struct objhead *, double ttl, double grace); void HSH_config(const char *h_arg); +struct objcore *HSH_NewObjCore(struct worker *wrk); #ifdef VARNISH_CACHE_CHILD diff --git a/bin/varnishd/storage/stevedore.c b/bin/varnishd/storage/stevedore.c index f1cbe94..53846a0 100644 --- a/bin/varnishd/storage/stevedore.c +++ b/bin/varnishd/storage/stevedore.c @@ -237,6 +237,7 @@ STV_MkObject(struct stevedore *stv, struct busyobj *bo, struct objcore **ocp, CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); CHECK_OBJ_NOTNULL(soc, STV_OBJ_SECRETES_MAGIC); AN(ocp); + CHECK_OBJ_NOTNULL((*ocp), OBJCORE_MAGIC); assert(PAOK(ptr)); assert(PAOK(soc->wsl)); @@ -262,17 +263,14 @@ STV_MkObject(struct stevedore *stv, struct busyobj *bo, struct objcore **ocp, VTAILQ_INIT(&o->store); bo->stats->n_object++; - if (*ocp != NULL) { - CHECK_OBJ_NOTNULL((*ocp), OBJCORE_MAGIC); - - o->objcore = *ocp; - *ocp = NULL; /* refcnt follows pointer. */ + o->objcore = *ocp; + *ocp = NULL; /* refcnt follows pointer. */ + if (o->objcore->objhead != NULL) BAN_NewObjCore(o->objcore); - o->objcore->methods = &default_oc_methods; - o->objcore->priv = o; - o->objcore->priv2 = (uintptr_t)stv; - } + o->objcore->methods = &default_oc_methods; + o->objcore->priv = o; + o->objcore->priv2 = (uintptr_t)stv; return (o); } @@ -356,8 +354,11 @@ STV_NewObject(struct busyobj *bo, struct objcore **ocp, const char *hint, } } - if (o == NULL) + if (o == NULL) { + AN(*ocp); return (NULL); + } + AZ(*ocp); CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(o->objstore, STORAGE_MAGIC); return (o); From phk at varnish-cache.org Mon May 21 07:24:12 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Mon, 21 May 2012 09:24:12 +0200 Subject: [master] 3f56d4e Fix ttl when backend fetches are salvaged into transient storage. Message-ID: commit 3f56d4ebb4297f383cba2d05c2eca179eb171fe6 Author: Poul-Henning Kamp Date: Mon May 21 07:23:27 2012 +0000 Fix ttl when backend fetches are salvaged into transient storage. Submitted by: Martin Fixes #1140 diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c index 9b7a968..b350438 100644 --- a/bin/varnishd/cache/cache_center.c +++ b/bin/varnishd/cache/cache_center.c @@ -812,12 +812,12 @@ cnt_fetchbody(struct sess *sp, struct worker *wrk, struct req *req) * Try to salvage the transaction by allocating a * shortlived object on Transient storage. */ - req->obj = STV_NewObject(bo, &req->objcore, TRANSIENT_STORAGE, - l, nhttp); if (bo->exp.ttl > cache_param->shortlived) bo->exp.ttl = cache_param->shortlived; bo->exp.grace = 0.0; bo->exp.keep = 0.0; + req->obj = STV_NewObject(bo, &req->objcore, TRANSIENT_STORAGE, + l, nhttp); } bo->stats = NULL; if (req->obj == NULL) { diff --git a/bin/varnishtest/tests/r01140.vtc b/bin/varnishtest/tests/r01140.vtc new file mode 100644 index 0000000..4bd0b3b --- /dev/null +++ b/bin/varnishtest/tests/r01140.vtc @@ -0,0 +1,39 @@ +varnishtest "Transient-salvaged objects ttl should be shortened - #1140" + +server s1 { + # This response should almost completely fill the storage + rxreq + expect req.url == /url1 + txresp -bodylen 1048050 + + # The next one should not fit in the storage, ending up in transient + # with zero ttl (=shortlived) + rxreq + expect req.url == /url2 + txresp -bodylen 1024 + + # And therefore this one should be fetched next + rxreq + expect req.url == /url2 + txresp -bodylen 1025 +} -start + +varnish v1 -arg "-p expiry_sleep=0.01 -p nuke_limit=0 -p shortlived=0" \ + -storage "-smalloc,1m" -vcl+backend { } -start + +client c1 { + txreq -url /url1 + rxresp + expect resp.status == 200 + expect resp.bodylen == 1048050 + + txreq -url /url2 + rxresp + expect resp.status == 200 + expect resp.bodylen == 1024 + + txreq -url /url2 + rxresp + expect resp.status == 200 + expect resp.bodylen == 1025 +} -run From phk at varnish-cache.org Mon May 21 08:12:43 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Mon, 21 May 2012 10:12:43 +0200 Subject: [master] 304683c Adopt Martins fixed for #1138, which is mostly an artifact of me being interrupted half-way through committing a bunch of stuff. Message-ID: commit 304683cc17f4bbf39fb6eb35443e40d2755867cd Author: Poul-Henning Kamp Date: Mon May 21 08:11:04 2012 +0000 Adopt Martins fixed for #1138, which is mostly an artifact of me being interrupted half-way through committing a bunch of stuff. I'm passing on the test-case for two reasons: The code is in flux and it will soon be obsolete, and second "delay 0.2" testcases are notoriously flakey. Submitted by: Martin Fixes #1138 diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c index b350438..d96bd8e 100644 --- a/bin/varnishd/cache/cache_center.c +++ b/bin/varnishd/cache/cache_center.c @@ -324,7 +324,7 @@ cnt_deliver(struct sess *sp, struct worker *wrk, struct req *req) assert(bo->state >= BOS_FAILED); if (bo->state == BOS_FAILED) { - req->obj = NULL; + HSH_Deref(&wrk->stats, NULL, &req->obj); VBO_DerefBusyObj(wrk, &req->busyobj); req->err_code = 503; sp->step = STP_ERROR; @@ -900,7 +900,7 @@ cnt_fetchbody(struct sess *sp, struct worker *wrk, struct req *req) VBO_DerefBusyObj(wrk, &req->busyobj); } else if (bo->state == BOS_FAILED) { /* handle early failures */ - req->obj = NULL; + HSH_Deref(&wrk->stats, NULL, &req->obj); VBO_DerefBusyObj(wrk, &req->busyobj); req->err_code = 503; sp->step = STP_ERROR; diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c index 7e9a25c..bc0e52c 100644 --- a/bin/varnishd/cache/cache_fetch.c +++ b/bin/varnishd/cache/cache_fetch.c @@ -645,8 +645,9 @@ FetchBody(struct worker *wrk, void *priv) if (bo->state == BOS_FAILED) { wrk->stats.fetch_failed++; VDI_CloseFd(&bo->vbc); - obj->exp.ttl = -1.; obj->len = 0; + EXP_Clr(&obj->exp); + EXP_Rearm(obj); } else { assert(bo->state == BOS_FETCHING); From phk at varnish-cache.org Mon May 21 12:10:29 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Mon, 21 May 2012 14:10:29 +0200 Subject: [master] e0c87d4 Move the HTTP-conditional check up before we call vcl_deliver{}, there is plenty of opportunity to prevent conditional delivery in all the other vcl_*{}'s and there is a value in exposing the actual response. Message-ID: commit e0c87d41cf1fb90442d5c2cd524ab9f88cb06dc1 Author: Poul-Henning Kamp Date: Mon May 21 12:09:02 2012 +0000 Move the HTTP-conditional check up before we call vcl_deliver{}, there is plenty of opportunity to prevent conditional delivery in all the other vcl_*{}'s and there is a value in exposing the actual response. diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c index d96bd8e..48fdfe4 100644 --- a/bin/varnishd/cache/cache_center.c +++ b/bin/varnishd/cache/cache_center.c @@ -266,6 +266,15 @@ cnt_prepresp(struct sess *sp, struct worker *wrk, struct req *req) } HTTP_Setup(req->resp, req->ws, req->vsl, HTTP_Resp); RES_BuildHttp(sp); + + if (req->obj->response == 200 + && req->http->conds && RFC2616_Do_Cond(sp)) { + req->wantbody = 0; + http_SetResp(req->resp, "HTTP/1.1", 304, "Not Modified"); + http_Unset(req->resp, H_Content_Length); + http_Unset(req->resp, H_Transfer_Encoding); + } + VCL_deliver_method(sp); switch (req->handling) { case VCL_RET_DELIVER: diff --git a/bin/varnishd/cache/cache_response.c b/bin/varnishd/cache/cache_response.c index cd45945..f92ca81 100644 --- a/bin/varnishd/cache/cache_response.c +++ b/bin/varnishd/cache/cache_response.c @@ -234,17 +234,6 @@ RES_WriteObj(struct sess *sp) req = sp->req; CHECK_OBJ_NOTNULL(req, REQ_MAGIC); - WRW_Reserve(sp->wrk, &sp->fd, sp->req->vsl, sp->req->t_resp); - - if (req->obj->response == 200 && - req->http->conds && - RFC2616_Do_Cond(sp)) { - req->wantbody = 0; - http_SetResp(req->resp, "HTTP/1.1", 304, "Not Modified"); - http_Unset(req->resp, H_Content_Length); - http_Unset(req->resp, H_Transfer_Encoding); - } - /* * If nothing special planned, we can attempt Range support */ @@ -265,6 +254,8 @@ RES_WriteObj(struct sess *sp) if (req->res_mode & RES_GUNZIP) http_Unset(req->resp, H_Content_Encoding); + WRW_Reserve(sp->wrk, &sp->fd, sp->req->vsl, sp->req->t_resp); + /* * Send HTTP protocol header, unless interior ESI object */ From phk at varnish-cache.org Mon May 21 13:18:43 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Mon, 21 May 2012 15:18:43 +0200 Subject: [master] 44c0c6e Collect all aspect of resp.* creation together. Message-ID: commit 44c0c6edaf84a9800382e2db6cdd8c0f62643bb7 Author: Poul-Henning Kamp Date: Mon May 21 13:17:50 2012 +0000 Collect all aspect of resp.* creation together. diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c index 48fdfe4..81b2b3b 100644 --- a/bin/varnishd/cache/cache_center.c +++ b/bin/varnishd/cache/cache_center.c @@ -267,14 +267,6 @@ cnt_prepresp(struct sess *sp, struct worker *wrk, struct req *req) HTTP_Setup(req->resp, req->ws, req->vsl, HTTP_Resp); RES_BuildHttp(sp); - if (req->obj->response == 200 - && req->http->conds && RFC2616_Do_Cond(sp)) { - req->wantbody = 0; - http_SetResp(req->resp, "HTTP/1.1", 304, "Not Modified"); - http_Unset(req->resp, H_Content_Length); - http_Unset(req->resp, H_Transfer_Encoding); - } - VCL_deliver_method(sp); switch (req->handling) { case VCL_RET_DELIVER: diff --git a/bin/varnishd/cache/cache_response.c b/bin/varnishd/cache/cache_response.c index f92ca81..82cdafc 100644 --- a/bin/varnishd/cache/cache_response.c +++ b/bin/varnishd/cache/cache_response.c @@ -124,7 +124,15 @@ RES_BuildHttp(const struct sess *sp) http_SetHeader(req->resp, "Accept-Ranges: bytes"); } - if (req->res_mode & RES_CHUNKED) + if (req->res_mode & RES_GUNZIP) + http_Unset(req->resp, H_Content_Encoding); + + if (req->obj->response == 200 + && req->http->conds && RFC2616_Do_Cond(sp)) { + req->wantbody = 0; + http_SetResp(req->resp, "HTTP/1.1", 304, "Not Modified"); + http_Unset(req->resp, H_Content_Length); + } else if (req->res_mode & RES_CHUNKED) http_SetHeader(req->resp, "Transfer-Encoding: chunked"); http_Unset(req->resp, H_Date); @@ -248,12 +256,6 @@ RES_WriteObj(struct sess *sp) http_GetHdr(req->http, H_Range, &r)) res_dorange(sp, r, &low, &high); - /* - * Always remove C-E if client don't grok it - */ - if (req->res_mode & RES_GUNZIP) - http_Unset(req->resp, H_Content_Encoding); - WRW_Reserve(sp->wrk, &sp->fd, sp->req->vsl, sp->req->t_resp); /* From apj at varnish-cache.org Thu May 24 12:18:16 2012 From: apj at varnish-cache.org (Andreas Plesner Jacobsen) Date: Thu, 24 May 2012 14:18:16 +0200 Subject: [master] 7755ce5 Duration needs a unit Message-ID: commit 7755ce56a67e03a0f8f7e6cccbaa6992c5951619 Author: Andreas Plesner Jacobsen Date: Thu May 24 14:17:52 2012 +0200 Duration needs a unit diff --git a/doc/sphinx/reference/vmod_std.rst b/doc/sphinx/reference/vmod_std.rst index a1ece16..984331e 100644 --- a/doc/sphinx/reference/vmod_std.rst +++ b/doc/sphinx/reference/vmod_std.rst @@ -124,7 +124,7 @@ Description the usual s (seconds), m (minutes), h (hours), d (days) and w (weeks) units. If *s* fails to parse, *fallback* will be used. Example - set beresp.ttl = std.duration("1w", 3600); + set beresp.ttl = std.duration("1w", 3600s); integer -------- From tfheen at varnish-cache.org Thu May 24 12:47:41 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:41 +0200 Subject: [3.0] 1b93331 remove the experimental flag from http_range_support Message-ID: commit 1b933317b9b9f6a777f9a45908deb37e28470b38 Author: Per Buer Date: Thu Jan 19 10:54:34 2012 +0100 remove the experimental flag from http_range_support diff --git a/bin/varnishd/mgt_param.c b/bin/varnishd/mgt_param.c index 76d9fe2..16bbb7d 100644 --- a/bin/varnishd/mgt_param.c +++ b/bin/varnishd/mgt_param.c @@ -870,7 +870,7 @@ static const struct parspec input_parspec[] = { "10", "objects" }, { "http_range_support", tweak_bool, &master.http_range_support, 0, 0, "Enable support for HTTP Range headers.\n", - EXPERIMENTAL, + 0, "on", "bool" }, { "http_gzip_support", tweak_bool, &master.http_gzip_support, 0, 0, "Enable gzip support. When enabled Varnish will compress " From tfheen at varnish-cache.org Thu May 24 12:47:41 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:41 +0200 Subject: [3.0] 302d463 Force lookup of kss resources and fix cached creation of objects in Plone Message-ID: commit 302d463c84cc5c6d0818db585bbb886bbd1c72cc Author: Cleber J Santos Date: Wed Jan 18 11:46:03 2012 -0200 Force lookup of kss resources and fix cached creation of objects in Plone diff --git a/etc/zope-plone.vcl b/etc/zope-plone.vcl index b69f583..263e343 100644 --- a/etc/zope-plone.vcl +++ b/etc/zope-plone.vcl @@ -52,13 +52,18 @@ sub vcl_recv { } return(lookup); } + + # Do not cache the creation of objects in Plone + if (req.url ~ "createObject"){ + return(pass); + } } # Don't cache authenticated requests if (req.http.Cookie && req.http.Cookie ~ "__ac(|_(name|password|persistent))=") { # Force lookup of specific urls unlikely to need protection - if (req.url ~ "\.(js|css)") { + if (req.url ~ "\.(js|css|kss)") { remove req.http.cookie; return(lookup); } From tfheen at varnish-cache.org Thu May 24 12:47:42 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:42 +0200 Subject: [3.0] b1d132c Don't try to stream when there is no body. Message-ID: commit b1d132c5e22ad37da0fc7c642373417052bbbe94 Author: Tollef Fog Heen Date: Wed May 23 13:28:30 2012 +0200 Don't try to stream when there is no body. diff --git a/bin/varnishd/cache_center.c b/bin/varnishd/cache_center.c index b3d7237..b2b9a45 100644 --- a/bin/varnishd/cache_center.c +++ b/bin/varnishd/cache_center.c @@ -747,6 +747,10 @@ cnt_fetchbody(struct sess *sp) if (!sp->wantbody) sp->wrk->do_stream = 0; + /* No reason to try streaming a non-existing body */ + if (sp->wrk->body_status == BS_NONE) + sp->wrk->do_stream = 0; + l = http_EstimateWS(sp->wrk->beresp, pass ? HTTPH_R_PASS : HTTPH_A_INS, &nhttp); From tfheen at varnish-cache.org Thu May 24 12:47:42 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:42 +0200 Subject: [3.0] b28e204 typo Message-ID: commit b28e20472e7ca46859781854caf4c9aa7a1c6481 Author: Lasse Karstensen Date: Mon Feb 6 14:29:39 2012 +0100 typo diff --git a/lib/libvcl/vcc_expr.c b/lib/libvcl/vcc_expr.c index 1f1c274..0c885c0 100644 --- a/lib/libvcl/vcc_expr.c +++ b/lib/libvcl/vcc_expr.c @@ -51,7 +51,7 @@ vcc_Type(enum var_type fmt) #include "vcc_types.h" #undef VCC_TYPE default: - assert("Unknwon Type"); + assert("Unknown Type"); return(NULL); } } From tfheen at varnish-cache.org Thu May 24 12:47:42 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:42 +0200 Subject: [3.0] a00d608 Allocate HTTP.status from http's designated workspace. Message-ID: commit a00d6085e6a25613ba97862c97bd3dc9bf1e7094 Author: Poul-Henning Kamp Date: Wed Feb 8 23:26:57 2012 +0000 Allocate HTTP.status from http's designated workspace. diff --git a/bin/varnishd/cache_http.c b/bin/varnishd/cache_http.c index 5ce1b6a..76b3f86 100644 --- a/bin/varnishd/cache_http.c +++ b/bin/varnishd/cache_http.c @@ -1078,7 +1078,7 @@ http_Write(struct worker *w, const struct http *hp, int resp) l = WRW_WriteH(w, &hp->hd[HTTP_HDR_PROTO], " "); WSLH(w, fd, hp, HTTP_HDR_PROTO); - hp->hd[HTTP_HDR_STATUS].b = WS_Alloc(w->ws, 4); + hp->hd[HTTP_HDR_STATUS].b = WS_Alloc(hp->ws, 4); AN(hp->hd[HTTP_HDR_STATUS].b); sprintf(hp->hd[HTTP_HDR_STATUS].b, "%3d", hp->status); From tfheen at varnish-cache.org Thu May 24 12:47:42 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:42 +0200 Subject: [3.0] 6590e65 Most of these variables are not available in vcl_deliver Message-ID: commit 6590e6561996f0d9c9cd99178b3b936899dcc918 Author: Andreas Plesner Jacobsen Date: Thu Feb 16 19:53:59 2012 +0100 Most of these variables are not available in vcl_deliver Fixes #1056 diff --git a/doc/sphinx/reference/vcl.rst b/doc/sphinx/reference/vcl.rst index 5d3030f..ff92c56 100644 --- a/doc/sphinx/reference/vcl.rst +++ b/doc/sphinx/reference/vcl.rst @@ -836,7 +836,8 @@ beresp.storage After the object is entered into the cache, the following (mostly read-only) variables are available when the object has been located in -cache, typically in vcl_hit and vcl_deliver. +cache, typically in vcl_hit, or when constructing a synthetic reply in +vcl_error: obj.proto The HTTP protocol version used when the object was retrieved. @@ -852,11 +853,12 @@ obj.ttl obj.lastuse The approximate time elapsed since the object was last requests, in - seconds. + seconds. This variable is also available in vcl_deliver. obj.hits The approximate number of times the object has been delivered. A value - of 0 indicates a cache miss. + of 0 indicates a cache miss. This variable is also available in + vcl_deliver. obj.grace The object's grace period in seconds. obj.grace is writable. From tfheen at varnish-cache.org Thu May 24 12:47:42 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:42 +0200 Subject: [3.0] c987fa8 Add more info about changes from 2.1 to 3.0. Thanks to xcir.net for inspiration. Message-ID: commit c987fa8798760b5be55060264d54b9a5b9f30850 Author: Andreas Plesner Jacobsen Date: Fri Feb 24 12:16:25 2012 +0100 Add more info about changes from 2.1 to 3.0. Thanks to xcir.net for inspiration. diff --git a/doc/sphinx/installation/upgrade.rst b/doc/sphinx/installation/upgrade.rst index 0ed4f9f..cee17b8 100644 --- a/doc/sphinx/installation/upgrade.rst +++ b/doc/sphinx/installation/upgrade.rst @@ -60,10 +60,10 @@ becomes:: } } -``beresp.cacheable`` is gone -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``beresp.cacheable`` and ``obj.cacheable``is gone +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -``beresp.cacheable`` is gone, and can be replaced with ``beresp.ttl > 0s`` +``beresp.cacheable`` is gone, and can be replaced with ``beresp.ttl > 0s``. Similarly ``obj.cacheable`` can be replaced with ``obj.ttl > 0s``. returns are now done with the ``return()`` function ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -111,6 +111,56 @@ The difference in behaviour of ``pass`` in ``vcl_recv`` and different, you must now do ``return(hit_for_pass)`` when doing a pass in ``vcl_fetch``. +Changes to runtime parameters +============================= + +Deleted parameters +~~~~~~~~~~~~~~~~~~ + +``cache_vbe_conns`` and ``err_ttl`` has been removed. + +New parameters +~~~~~~~~~~~~~~ + +The following parameters have been added, see man varnishd for reference: +* ``default_keep`` +* ``expiry_sleep`` +* ``fetch_maxchunksize`` +* ``gzip_level`` +* ``gzip_memlevel`` +* ``gzip_stack_buffer`` +* ``gzip_tmp_space`` +* ``gzip_window`` +* ``http_gzip_support`` +* ``http_req_hdr_len`` +* ``http_req_size`` +* ``http_resp_hdr_len`` +* ``http_resp_size`` +* ``shortlived`` +* ``thread_pool_workspace`` +* ``vcc_err_unref`` +* ``vcl_dir`` +* ``vmod_dir`` + +Changed default values +~~~~~~~~~~~~~~~~~~~~~~ + +The following parameters have new defaults: + +* ``ban_lurker_sleep`` changed from 0 to 0.01 seconds, enabling the ban lurker by default. +* ``connect_timeout`` changed from 0.4 to 0.7 seconds. +* ``log_hashstring`` changed from off to on. +* ``send_timeout`` changed from 60 to 60 seconds. +* ``thread_pool_add_delay`` changed from 20 to 2 ms. + +Changed parameter names +~~~~~~~~~~~~~~~~~~~~~~~ + +The following parameters have new names: +* ``http_headers`` has been renamed to ``http_max_hdr``. +* ``max_esi_includes`` has been renamed to ``max_esi_depth``. +* ``overflow_max`` has been renamed to ``queue_max``. +* ``purge_dups`` has been renamed to ``ban_dups``. Changes to behaviour ==================== From tfheen at varnish-cache.org Thu May 24 12:47:42 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:42 +0200 Subject: [3.0] a636c01 Detect client crashing during startup Message-ID: commit a636c010cbb767a4610d8d6b11f97e15d027bbce Author: Poul-Henning Kamp Date: Sun Feb 19 11:05:09 2012 +0000 Detect client crashing during startup diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c index dec9754..1b3b445 100644 --- a/bin/varnishtest/vtc_varnish.c +++ b/bin/varnishtest/vtc_varnish.c @@ -159,6 +159,12 @@ wait_running(const struct varnish *v) if (st != CLIS_OK) vtc_log(v->vl, 0, "CLI status command failed: %u %s", st, r); + if (!strcmp(r, "Child in state stopped")) { + vtc_log(v->vl, 0, + "Child stopped before running: %u %s", st, r); + free(r); + break; + } if (!strcmp(r, "Child in state running")) { free(r); break; From tfheen at varnish-cache.org Thu May 24 12:47:42 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:42 +0200 Subject: [3.0] 7160b84 Grammar Message-ID: commit 7160b841a89bfc39ec4d19fbace5ecbc9af26e28 Author: Andreas Plesner Jacobsen Date: Fri Feb 24 14:52:38 2012 +0100 Grammar diff --git a/doc/sphinx/installation/upgrade.rst b/doc/sphinx/installation/upgrade.rst index 2402af0..2c06a3f 100644 --- a/doc/sphinx/installation/upgrade.rst +++ b/doc/sphinx/installation/upgrade.rst @@ -60,8 +60,8 @@ becomes:: } } -``beresp.cacheable`` and ``obj.cacheable``is gone -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``beresp.cacheable`` and ``obj.cacheable`` are gone +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``beresp.cacheable`` is gone, and can be replaced with ``beresp.ttl > 0s``. Similarly ``obj.cacheable`` can be replaced with ``obj.ttl > 0s``. From tfheen at varnish-cache.org Thu May 24 12:47:42 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:42 +0200 Subject: [3.0] 9154117 Fix syntax Message-ID: commit 91541177ee3d9e3501a3ee701bd751d2ce305bfb Author: Andreas Plesner Jacobsen Date: Fri Feb 24 12:20:37 2012 +0100 Fix syntax diff --git a/doc/sphinx/installation/upgrade.rst b/doc/sphinx/installation/upgrade.rst index cee17b8..2402af0 100644 --- a/doc/sphinx/installation/upgrade.rst +++ b/doc/sphinx/installation/upgrade.rst @@ -123,6 +123,7 @@ New parameters ~~~~~~~~~~~~~~ The following parameters have been added, see man varnishd for reference: + * ``default_keep`` * ``expiry_sleep`` * ``fetch_maxchunksize`` @@ -157,6 +158,7 @@ Changed parameter names ~~~~~~~~~~~~~~~~~~~~~~~ The following parameters have new names: + * ``http_headers`` has been renamed to ``http_max_hdr``. * ``max_esi_includes`` has been renamed to ``max_esi_depth``. * ``overflow_max`` has been renamed to ``queue_max``. From tfheen at varnish-cache.org Thu May 24 12:47:42 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:42 +0200 Subject: [3.0] fdd168f Add short example on how to get Websockets to work Message-ID: commit fdd168f95e2bfa0ae2d6aebaec2124b4cb856f6c Author: Lasse Karstensen Date: Fri Feb 24 15:12:44 2012 +0100 Add short example on how to get Websockets to work diff --git a/doc/sphinx/tutorial/websockets.rst b/doc/sphinx/tutorial/websockets.rst new file mode 100644 index 0000000..a74353e --- /dev/null +++ b/doc/sphinx/tutorial/websockets.rst @@ -0,0 +1,20 @@ + +Using Websockets +---------------- + +Websockets is a technology for creating a bidirectional stream-based channel over HTTP. + +To run websockets through Varnish you need to pipe it, and copy the Upgrade header. Use the following +VCL config to do so:: + + sub vcl_pipe { + if (req.http.upgrade) { + set bereq.http.upgrade = req.http.upgrade; + } + } + sub vcl_recv { + if (req.http.Upgrade ~ "(?i)websocket") { + return (pipe); + } + } + From tfheen at varnish-cache.org Thu May 24 12:47:42 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:42 +0200 Subject: [3.0] 0358917 Add short example on how to get Websockets to work (#2) Message-ID: commit 0358917a6edaea5a4798a83e0a3dc0f6ca5b5ab8 Author: Lasse Karstensen Date: Fri Feb 24 15:14:12 2012 +0100 Add short example on how to get Websockets to work (#2) diff --git a/doc/sphinx/tutorial/index.rst b/doc/sphinx/tutorial/index.rst index c3a05f5..6769ec4 100644 --- a/doc/sphinx/tutorial/index.rst +++ b/doc/sphinx/tutorial/index.rst @@ -29,6 +29,7 @@ separate topic. Good luck. compression esi virtualised + websockets advanced_backend_servers handling_misbehaving_servers advanced_topics From tfheen at varnish-cache.org Thu May 24 12:47:42 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:42 +0200 Subject: [3.0] f262a57 Correct value for 2.1 Message-ID: commit f262a5714224dc585d1e217a9345e2604838859f Author: Andreas Plesner Jacobsen Date: Fri Feb 24 15:16:15 2012 +0100 Correct value for 2.1 diff --git a/doc/sphinx/installation/upgrade.rst b/doc/sphinx/installation/upgrade.rst index 2c06a3f..93446ea 100644 --- a/doc/sphinx/installation/upgrade.rst +++ b/doc/sphinx/installation/upgrade.rst @@ -151,7 +151,7 @@ The following parameters have new defaults: * ``ban_lurker_sleep`` changed from 0 to 0.01 seconds, enabling the ban lurker by default. * ``connect_timeout`` changed from 0.4 to 0.7 seconds. * ``log_hashstring`` changed from off to on. -* ``send_timeout`` changed from 60 to 60 seconds. +* ``send_timeout`` changed from 600 to 60 seconds. * ``thread_pool_add_delay`` changed from 20 to 2 ms. Changed parameter names From tfheen at varnish-cache.org Thu May 24 12:47:42 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:42 +0200 Subject: [3.0] 0938a2e Drop the body of hit-for-pass objects once we have delivered them to the original requester. Message-ID: commit 0938a2ed1903a397d02640a60f4d977baf818267 Author: Poul-Henning Kamp Date: Mon Feb 27 08:31:41 2012 +0000 Drop the body of hit-for-pass objects once we have delivered them to the original requester. Submitted by: DocWilco diff --git a/bin/varnishd/cache_center.c b/bin/varnishd/cache_center.c index b2b9a45..bf08fb0 100644 --- a/bin/varnishd/cache_center.c +++ b/bin/varnishd/cache_center.c @@ -276,6 +276,13 @@ cnt_deliver(struct sess *sp) RES_WriteObj(sp); + /* No point in saving the body if it is hit-for-pass */ + if (sp->obj->objcore != NULL) { + CHECK_OBJ_NOTNULL(sp->obj->objcore, OBJCORE_MAGIC); + if (sp->obj->objcore->flags & OC_F_PASS) + STV_Freestore(sp->obj); + } + assert(WRW_IsReleased(sp->wrk)); assert(sp->wrk->wrw.ciov == sp->wrk->wrw.siov); (void)HSH_Deref(sp->wrk, NULL, &sp->obj); From tfheen at varnish-cache.org Thu May 24 12:47:42 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:42 +0200 Subject: [3.0] 9528984 Avoid taking the saintmode lock if the list empty. Message-ID: commit 95289844b65349f15e9449cafc907ca7c2057451 Author: Poul-Henning Kamp Date: Mon Feb 27 08:47:12 2012 +0000 Avoid taking the saintmode lock if the list empty. Submitted by: DocWilco diff --git a/bin/varnishd/cache_backend.c b/bin/varnishd/cache_backend.c index 756d659..7e36bda 100644 --- a/bin/varnishd/cache_backend.c +++ b/bin/varnishd/cache_backend.c @@ -268,16 +268,15 @@ vbe_Healthy(const struct vdi_simple *vs, const struct sess *sp) /* VRT/VCC sets threshold to UINT_MAX to mark that it's not * specified by VCL (thus use param). */ - if (vs->vrt->saintmode_threshold == UINT_MAX) + threshold = vs->vrt->saintmode_threshold; + if (threshold == UINT_MAX) threshold = params->saintmode_threshold; - else - threshold = vs->vrt->saintmode_threshold; if (backend->admin_health == ah_healthy) threshold = UINT_MAX; - /* Saintmode is disabled */ - if (threshold == 0) + /* Saintmode is disabled, or list is empty */ + if (threshold == 0 || VTAILQ_EMPTY(&backend->troublelist)) return (1); if (sp->objcore == NULL) From tfheen at varnish-cache.org Thu May 24 12:47:42 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:42 +0200 Subject: [3.0] 36eb0b0 3.0 syntax Message-ID: commit 36eb0b093e4faa06367e301dd7fc0346f0e846d0 Author: Andreas Plesner Jacobsen Date: Sun Mar 4 16:48:45 2012 +0100 3.0 syntax diff --git a/doc/sphinx/tutorial/increasing_your_hitrate.rst b/doc/sphinx/tutorial/increasing_your_hitrate.rst index 83236d6..73d983e 100644 --- a/doc/sphinx/tutorial/increasing_your_hitrate.rst +++ b/doc/sphinx/tutorial/increasing_your_hitrate.rst @@ -146,7 +146,7 @@ header. You could easily add support for this header in VCL. In vcl_fetch:: if (beresp.http.Pragma ~ "nocache") { - pass; + return(pass); } Authorization From tfheen at varnish-cache.org Thu May 24 12:47:43 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:43 +0200 Subject: [3.0] 68e7342 Grammar in varnishncsa man page Message-ID: commit 68e73421cf12ddb4a3ae8c8da362a65acd823b1d Author: Tollef Fog Heen Date: Wed Mar 7 14:18:24 2012 +0100 Grammar in varnishncsa man page diff --git a/doc/sphinx/reference/varnishncsa.rst b/doc/sphinx/reference/varnishncsa.rst index 9373f5c..2937b26 100644 --- a/doc/sphinx/reference/varnishncsa.rst +++ b/doc/sphinx/reference/varnishncsa.rst @@ -64,7 +64,7 @@ The following options are available: Defaults to 127.0.0.1 for backend requests. %{X}i - The contents of request header line X. + The contents of request header X. %l Remote logname (always '-') @@ -77,7 +77,7 @@ The following options are available: empty string. %{X}o - The contents of response header line X. + The contents of response header X. %r The first line of the request. Synthesized from other From tfheen at varnish-cache.org Thu May 24 12:47:43 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:43 +0200 Subject: [3.0] 2efdcc3 Fixing a typo in the documentation. Message-ID: commit 2efdcc3884c822c6640372c5d7fafed8d6d1b85d Author: Derek Hammer Date: Thu Mar 8 03:11:26 2012 -0500 Fixing a typo in the documentation. diff --git a/doc/sphinx/tutorial/purging.rst b/doc/sphinx/tutorial/purging.rst index 5e5768e..22056a7 100644 --- a/doc/sphinx/tutorial/purging.rst +++ b/doc/sphinx/tutorial/purging.rst @@ -4,7 +4,7 @@ Purging and banning ===================== -One of the most effective way of increasing your hit ratio is to +One of the most effective ways of increasing your hit ratio is to increase the time-to-live (ttl) of your objects. But, as you're aware of, in this twitterific day of age serving content that is outdated is bad for business. From tfheen at varnish-cache.org Thu May 24 12:47:43 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:43 +0200 Subject: [3.0] 201bc8d Remove old Date: header before adding our new one. Message-ID: commit 201bc8d88a1f85f6caa97da94a8a6bf951afdbe2 Author: Poul-Henning Kamp Date: Fri Mar 9 09:58:41 2012 +0000 Remove old Date: header before adding our new one. Submitted by: scoof Fixes #1104 diff --git a/bin/varnishd/cache_response.c b/bin/varnishd/cache_response.c index 37459d7..5a0ee9e 100644 --- a/bin/varnishd/cache_response.c +++ b/bin/varnishd/cache_response.c @@ -133,6 +133,7 @@ RES_BuildHttp(const struct sess *sp) http_SetHeader(sp->wrk, sp->fd, sp->wrk->resp, "Transfer-Encoding: chunked"); + http_Unset(sp->wrk->resp, H_Date); TIM_format(TIM_real(), time_str); http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp, "Date: %s", time_str); From tfheen at varnish-cache.org Thu May 24 12:47:43 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:43 +0200 Subject: [3.0] 527376f Small doc fixes Message-ID: commit 527376f6515944300b6e47e06d7efe8f1d397367 Author: Andreas Plesner Jacobsen Date: Mon Mar 12 12:25:41 2012 +0100 Small doc fixes diff --git a/doc/sphinx/tutorial/logging.rst b/doc/sphinx/tutorial/logging.rst index 68f1d87..1f0bc18 100644 --- a/doc/sphinx/tutorial/logging.rst +++ b/doc/sphinx/tutorial/logging.rst @@ -9,7 +9,7 @@ memory segment. When the end of the segment is reached we start over, overwriting old data. This is much, much faster then logging to a file and it doesn't require disk space. -The flip side is that if you forget to have program actually write the +The flip side is that if you forget to have a program actually write the logs to disk they will disappear. varnishlog is one of the programs you can use to look at what Varnish diff --git a/doc/sphinx/tutorial/vcl.rst b/doc/sphinx/tutorial/vcl.rst index 7171ab6..54bce37 100644 --- a/doc/sphinx/tutorial/vcl.rst +++ b/doc/sphinx/tutorial/vcl.rst @@ -135,7 +135,7 @@ down for, uhm, examples. Example 1 - manipulating headers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Lets say we want to remove the cookie for all objects in the /static +Lets say we want to remove the cookie for all objects in the /images directory of our web server:: sub vcl_recv { From tfheen at varnish-cache.org Thu May 24 12:47:43 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:43 +0200 Subject: [3.0] e2d35b4 Fix for #1109 Message-ID: commit e2d35b4a3c514acf4d5bdf5cdba86682783475b1 Author: Poul-Henning Kamp Date: Tue Apr 10 12:03:16 2012 +0000 Fix for #1109 I've opted for a less intrusive fix that Martin proposed, but my fix is largely a rework of his suggested patch. Testcase by: Martin diff --git a/bin/varnishd/cache_esi_deliver.c b/bin/varnishd/cache_esi_deliver.c index cc3f569..bdb4357 100644 --- a/bin/varnishd/cache_esi_deliver.c +++ b/bin/varnishd/cache_esi_deliver.c @@ -440,12 +440,10 @@ ved_deliver_byterange(const struct sess *sp, ssize_t low, ssize_t high) ssize_t l, lx; u_char *p; -//printf("BR %jd %jd\n", low, high); lx = 0; VTAILQ_FOREACH(st, &sp->obj->store, list) { p = st->ptr; l = st->len; -//printf("[0-] %jd %jd\n", lx, lx + l); if (lx + l < low) { lx += l; continue; @@ -458,16 +456,14 @@ ved_deliver_byterange(const struct sess *sp, ssize_t low, ssize_t high) l -= (low - lx); lx = low; } -//printf("[1-] %jd %jd\n", lx, lx + l); if (lx + l >= high) l = high - lx; -//printf("[2-] %jd %jd\n", lx, lx + l); assert(lx >= low && lx + l <= high); if (l != 0) (void)WRW_Write(sp->wrk, p, l); - if (lx + st->len > high) + if (p + l < st->ptr + st->len) return(p[l]); - lx += st->len; + lx += l; } INCOMPL(); } @@ -478,10 +474,12 @@ ESI_DeliverChild(const struct sess *sp) struct storage *st; struct object *obj; ssize_t start, last, stop, lpad; - u_char *p, cc; + u_char cc; uint32_t icrc; uint32_t ilen; uint8_t *dbits; + int i, j; + uint8_t tailbuf[8]; if (!sp->obj->gziped) { VTAILQ_FOREACH(st, &sp->obj->store, list) @@ -561,12 +559,21 @@ ESI_DeliverChild(const struct sess *sp) } if (lpad > 0) (void)WRW_Write(sp->wrk, dbits + 1, lpad); + + /* We need the entire tail, but it may not be in one storage segment */ st = VTAILQ_LAST(&sp->obj->store, storagehead); - assert(st->len > 8); + for (i = sizeof tailbuf; i > 0; i -= j) { + j = st->len; + if (j > i) + j = i; + memcpy(tailbuf + i - j, st->ptr + st->len - j, j); + st = VTAILQ_PREV(st, storagehead, list); + assert(i == j || st != NULL); + } + + icrc = vle32dec(tailbuf); + ilen = vle32dec(tailbuf + 4); - p = st->ptr + st->len - 8; - icrc = vle32dec(p); - ilen = vle32dec(p + 4); sp->wrk->crc = crc32_combine(sp->wrk->crc, icrc, ilen); sp->wrk->l_crc += ilen; } diff --git a/bin/varnishtest/tests/r01109.vtc b/bin/varnishtest/tests/r01109.vtc new file mode 100644 index 0000000..50f0a0e --- /dev/null +++ b/bin/varnishtest/tests/r01109.vtc @@ -0,0 +1,43 @@ +varnishtest "Test case for #1109 - Gzip+ESI broken for large included objects" + +server s1 { + rxreq + expect req.url == "/test1" + txresp -body {startend} + rxreq + expect req.url == "/include1" + # This tests ESI+gzip delivery when the ESI-included object + # has more than one storage chunk + txresp -bodylen 4082 + + rxreq + txresp -body {startend} + expect req.url == "/test2" + + rxreq + expect req.url == "/include2" + # This tests gzip trailer extraction for ESI+gzip CRC calculation + # when the trailer spans two storage chunks + txresp -bodylen 4074 +} -start + +varnish v1 -arg "-pfetch_chunksize=4k" -arg "-pgzip_level=0" -vcl+backend { + sub vcl_fetch { + if (req.url ~ "/test") { + set beresp.do_esi = true; + } + set beresp.do_gzip = true; + } +} -start + +client c1 { + txreq -url "/test1" -hdr "Accept-Encoding: gzip" + rxresp + gunzip + expect resp.bodylen == 4096 + + txreq -url "/test2" -hdr "Accept-Encoding: gzip" + rxresp + gunzip + expect resp.bodylen == 4088 +} -run From tfheen at varnish-cache.org Thu May 24 12:47:43 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:43 +0200 Subject: [3.0] d499461 Stopgap fix to get FreeBSD 10-current compiling again. Message-ID: commit d499461fbe28d513211e6694ea22de88eb6e88a0 Author: Poul-Henning Kamp Date: Thu Apr 12 07:24:02 2012 +0000 Stopgap fix to get FreeBSD 10-current compiling again. diff --git a/bin/varnishadm/varnishadm.c b/bin/varnishadm/varnishadm.c index 68ebbf7..e67062f 100644 --- a/bin/varnishadm/varnishadm.c +++ b/bin/varnishadm/varnishadm.c @@ -38,7 +38,12 @@ #include #ifdef HAVE_LIBEDIT -#include +# include +# ifdef HAVE_EDIT_READLINE_READLINE_H +# include +# else +# include +# endif #endif #include "vcli.h" diff --git a/configure.ac b/configure.ac index 55b2281..0fbb620 100644 --- a/configure.ac +++ b/configure.ac @@ -150,6 +150,7 @@ AC_SUBST(PCRE_LIBS) PKG_CHECK_MODULES([LIBEDIT], [libedit], [AC_DEFINE([HAVE_LIBEDIT], [1], [Define we have libedit])], [AC_CHECK_HEADERS([readline/readline.h]) + AC_CHECK_HEADERS([edit/readline/readline.h]) AC_CHECK_LIB(edit, el_init, [ AC_DEFINE([HAVE_LIBEDIT], [1], [Define we have libedit]) LIBEDIT_CFLAGS="" From tfheen at varnish-cache.org Thu May 24 12:47:43 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:43 +0200 Subject: [3.0] b97fc0c Fix #1126 by properly setting the mask token to the IP number token. Message-ID: commit b97fc0cd048eb92ca7ad4f25b91e34837c5e1508 Author: Poul-Henning Kamp Date: Mon Apr 16 07:04:40 2012 +0000 Fix #1126 by properly setting the mask token to the IP number token. Varnishtest doesn't see the difference between a VCC core dump and a VCC error, so a test-case is non-trivial. Fixes #1126 diff --git a/lib/libvcl/vcc_acl.c b/lib/libvcl/vcc_acl.c index 30c9eea..272f3c6 100644 --- a/lib/libvcl/vcc_acl.c +++ b/lib/libvcl/vcc_acl.c @@ -265,8 +265,10 @@ vcc_acl_try_netnotation(struct vcc *tl, struct acl_e *ae) return (0); p += k + 1; } - if (ae->t_mask == NULL) + if (ae->t_mask == NULL) { ae->mask = 8 + 8 * i; + ae->t_mask = ae->t_addr; + } vcc_acl_add_entry(tl, ae, 4, b, AF_INET); return (1); } From tfheen at varnish-cache.org Thu May 24 12:47:43 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:43 +0200 Subject: [3.0] 87357ee Better fix for #1126 Message-ID: commit 87357eee9c5df596825ee3e0380d2c64b71de142 Author: Poul-Henning Kamp Date: Mon Apr 16 07:22:57 2012 +0000 Better fix for #1126 diff --git a/lib/libvcl/vcc_acl.c b/lib/libvcl/vcc_acl.c index 272f3c6..3e5ac6c 100644 --- a/lib/libvcl/vcc_acl.c +++ b/lib/libvcl/vcc_acl.c @@ -103,7 +103,10 @@ vcc_acl_add_entry(struct vcc *tl, const struct acl_e *ae, int l, if (fam == PF_INET && ae->mask > 32) { VSB_printf(tl->sb, "Too wide mask (%u) for IPv4 address", ae->mask); - vcc_ErrWhere(tl, ae->t_mask); + if (ae->t_mask != NULL) + vcc_ErrWhere(tl, ae->t_mask); + else + vcc_ErrWhere(tl, ae->t_addr); return; } if (fam == PF_INET6 && ae->mask > 128) { @@ -265,10 +268,8 @@ vcc_acl_try_netnotation(struct vcc *tl, struct acl_e *ae) return (0); p += k + 1; } - if (ae->t_mask == NULL) { + if (ae->t_mask == NULL) ae->mask = 8 + 8 * i; - ae->t_mask = ae->t_addr; - } vcc_acl_add_entry(tl, ae, 4, b, AF_INET); return (1); } From tfheen at varnish-cache.org Thu May 24 12:47:43 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:43 +0200 Subject: [3.0] c9366e5 :: need to be on a separate line in RST. Message-ID: commit c9366e5f2eaba0f27701a5bbe55862b6202e1cef Author: Per Buer Date: Mon Apr 16 13:37:47 2012 +0200 :: need to be on a separate line in RST. diff --git a/doc/sphinx/reference/vcl.rst b/doc/sphinx/reference/vcl.rst index ff92c56..01d783f 100644 --- a/doc/sphinx/reference/vcl.rst +++ b/doc/sphinx/reference/vcl.rst @@ -96,14 +96,16 @@ file as a quoted string. Backend declarations -------------------- -A backend declaration creates and initializes a named backend object:: +A backend declaration creates and initializes a named backend object: +:: backend www { .host = "www.example.com"; .port = "http"; } -The backend object can later be used to select a backend at request time:: +The backend object can later be used to select a backend at request time: +:: if (req.http.host ~ "(?i)^(www.)?example.com$") { set req.backend = www; @@ -118,7 +120,8 @@ backend connection, .first_byte_timeout for the time to wait for the first byte from the backend and .between_bytes_timeout for time to wait between each received byte. -These can be set in the declaration like this:: +These can be set in the declaration like this: +:: backend www { .host = "www.example.com"; @@ -145,7 +148,8 @@ be used. There are several types of directors. The different director types use different algorithms to choose which backend to use. -Configuring a director may look like this:: +Configuring a director may look like this: +:: director b2 random { .retries = 5; @@ -226,7 +230,8 @@ The DNS director ~~~~~~~~~~~~~~~~ The DNS director can use backends in two different ways. Either like the -random or round-robin director or using .list:: +random or round-robin director or using .list: +:: director directorname dns { .list = { @@ -266,7 +271,8 @@ considers them in the order in which they are listed in its definition. The fallback director does not take any options. -An example of a fallback director:: +An example of a fallback director: +:: director b3 fallback { { .backend = www1; } @@ -312,7 +318,8 @@ Probes take the following parameters: Default is 2 seconds. A backend with a probe can be defined like this, together with the -backend or director:: +backend or director: +:: backend www { .host = "www.example.com"; @@ -326,7 +333,8 @@ backend or director:: } } -Or it can be defined separately and then referenced:: +Or it can be defined separately and then referenced: +:: probe healthcheck { .url = "/status.cgi"; @@ -347,7 +355,8 @@ Or it can be defined separately and then referenced:: If you have many backends this can simplify the config a lot. -It is also possible to specify the raw HTTP request:: +It is also possible to specify the raw HTTP request: +:: probe rawprobe { # NB: \r\n automatically inserted after each string! @@ -361,7 +370,8 @@ ACLs ---- An ACL declaration creates and initializes a named access control list -which can later be used to match client addresses:: +which can later be used to match client addresses: +:: acl local { "localhost"; // myself @@ -375,7 +385,8 @@ if it is preceded by a negation mark, it will reject any address it is compared to, which may not be what you intended. If the entry is enclosed in parentheses, however, it will simply be ignored. -To match an IP address against an ACL, simply use the match operator:: +To match an IP address against an ACL, simply use the match operator: +:: if (client.ip ~ local) { return (pipe); @@ -390,7 +401,8 @@ PCRE(3) man page. To send flags to the PCRE engine, such as to turn on *case insensitivity* add the flag within parens following a question mark, -like this:: +like this: +:: if (req.http.host ~ "(?i)example.com$") { ... @@ -424,7 +436,8 @@ ban_url(regex) Subroutines ~~~~~~~~~~~ -A subroutine is used to group code for legibility or reusability:: +A subroutine is used to group code for legibility or reusability: +:: sub pipe_if_local { if (client.ip ~ local) { @@ -640,7 +653,8 @@ appear in the source. The default versions distributed with Varnish will be implicitly concatenated as a last resort at the end. -Example:: +Example: +:: # in file "main.vcl" include "backends.vcl"; @@ -887,7 +901,8 @@ resp.response resp.http.header The corresponding HTTP header. -Values may be assigned to variables using the set keyword:: +Values may be assigned to variables using the set keyword: +:: sub vcl_recv { # Normalize the Host: header @@ -896,7 +911,8 @@ Values may be assigned to variables using the set keyword:: } } -HTTP headers can be removed entirely using the remove keyword:: +HTTP headers can be removed entirely using the remove keyword: +:: sub vcl_fetch { # Don't cache cookies @@ -913,7 +929,8 @@ fresh object is being generated by the backend. The following vcl code will make Varnish serve expired objects. All object will be kept up to two minutes past their expiration time or a -fresh object is generated.:: +fresh object is generated. +:: sub vcl_recv { set req.grace = 2m; @@ -938,7 +955,8 @@ EXAMPLES The following code is the equivalent of the default configuration with the backend address set to "backend.example.com" and no backend port -specified:: +specified: +:: backend default { .host = "backend.example.com"; @@ -950,7 +968,8 @@ specified:: The following example shows how to support multiple sites running on separate backends in the same Varnish instance, by selecting backends -based on the request URL:: +based on the request URL: +:: backend www { .host = "www.example.com"; @@ -976,7 +995,8 @@ based on the request URL:: The following snippet demonstrates how to force a minimum TTL for all documents. Note that this is not the same as setting the default_ttl run-time parameter, as that only affects document for -which the backend did not specify a TTL:: +which the backend did not specify a TTL: +:: import std; # needed for std.log @@ -988,7 +1008,8 @@ which the backend did not specify a TTL:: } The following snippet demonstrates how to force Varnish to cache -documents even when cookies are present:: +documents even when cookies are present: +:: sub vcl_recv { if (req.request == "GET" && req.http.cookie) { @@ -1003,7 +1024,8 @@ documents even when cookies are present:: } The following code implements the HTTP PURGE method as used by Squid -for object invalidation:: +for object invalidation: +:: acl purge { "localhost"; From tfheen at varnish-cache.org Thu May 24 12:47:44 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:44 +0200 Subject: [3.0] cbd31d0 Fix escaping in regsub docs Message-ID: commit cbd31d0e3987608bdb842fc97664ef13e755e4ea Author: Tollef Fog Heen Date: Mon Apr 16 14:11:30 2012 +0200 Fix escaping in regsub docs diff --git a/doc/sphinx/reference/vcl.rst b/doc/sphinx/reference/vcl.rst index 212cd2b..927f640 100644 --- a/doc/sphinx/reference/vcl.rst +++ b/doc/sphinx/reference/vcl.rst @@ -420,9 +420,9 @@ hash_data(str) regsub(str, regex, sub) Returns a copy of str with the first occurrence of the regular - expression regex replaced with sub. Within sub, \\0 (which can - also be spelled &) is replaced with the entire matched string, - and \n is replaced with the contents of subgroup n in the + expression regex replaced with sub. Within sub, \\0 (which can + also be spelled \\&) is replaced with the entire matched string, + and \\n is replaced with the contents of subgroup n in the matched string. regsuball(str, regex, sub) From tfheen at varnish-cache.org Thu May 24 12:47:44 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:44 +0200 Subject: [3.0] 48a0c44 Stopped using macros for make and install, according to Fedora's packaging guidelines Message-ID: commit 48a0c44775b86c2b2e19a08461ec3c1bd3869ba9 Author: Ingvar Hagelund Date: Mon Apr 23 10:43:20 2012 +0200 Stopped using macros for make and install, according to Fedora's packaging guidelines diff --git a/redhat/varnish.spec b/redhat/varnish.spec index 5ecb85f..6f6d71e 100644 --- a/redhat/varnish.spec +++ b/redhat/varnish.spec @@ -98,7 +98,7 @@ cp bin/varnishd/default.vcl etc/zope-plone.vcl examples #sed -i 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g; # s|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' libtool -%{__make} %{?_smp_mflags} +make %{?_smp_mflags} head -6 etc/default.vcl > redhat/default.vcl @@ -138,7 +138,7 @@ cp -r doc/sphinx/\=build/html doc %endif %endif -%{__make} check LD_LIBRARY_PATH="../../lib/libvarnish/.libs:../../lib/libvarnishcompat/.libs:../../lib/libvarnishapi/.libs:../../lib/libvcl/.libs:../../lib/libvgz/.libs" +make check LD_LIBRARY_PATH="../../lib/libvarnish/.libs:../../lib/libvarnishcompat/.libs:../../lib/libvarnishapi/.libs:../../lib/libvcl/.libs:../../lib/libvgz/.libs" %install rm -rf %{buildroot} From tfheen at varnish-cache.org Thu May 24 12:47:44 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:44 +0200 Subject: [3.0] 2c4317d Stopped using macros for make and install, according to Fedora's packaging guidelines Message-ID: commit 2c4317d1338a9c451ea2de542f7894c5bb3e79e6 Author: Ingvar Hagelund Date: Mon Apr 23 10:50:41 2012 +0200 Stopped using macros for make and install, according to Fedora's packaging guidelines diff --git a/redhat/varnish.spec b/redhat/varnish.spec index 3391ed3..bde3705 100644 --- a/redhat/varnish.spec +++ b/redhat/varnish.spec @@ -153,13 +153,13 @@ find %{buildroot}/%{_libdir}/ -name '*.la' -exec rm -f {} ';' mkdir -p %{buildroot}/var/lib/varnish mkdir -p %{buildroot}/var/log/varnish mkdir -p %{buildroot}/var/run/varnish -%{__install} -D -m 0644 redhat/default.vcl %{buildroot}%{_sysconfdir}/varnish/default.vcl -%{__install} -D -m 0644 redhat/varnish.sysconfig %{buildroot}%{_sysconfdir}/sysconfig/varnish -%{__install} -D -m 0644 redhat/varnish.logrotate %{buildroot}%{_sysconfdir}/logrotate.d/varnish -%{__install} -D -m 0755 redhat/varnish.initrc %{buildroot}%{_initrddir}/varnish -%{__install} -D -m 0755 redhat/varnishlog.initrc %{buildroot}%{_initrddir}/varnishlog -%{__install} -D -m 0755 redhat/varnishncsa.initrc %{buildroot}%{_initrddir}/varnishncsa -%{__install} -D -m 0755 redhat/varnish_reload_vcl %{buildroot}%{_bindir}/varnish_reload_vcl +install -D -m 0644 redhat/default.vcl %{buildroot}%{_sysconfdir}/varnish/default.vcl +install -D -m 0644 redhat/varnish.sysconfig %{buildroot}%{_sysconfdir}/sysconfig/varnish +install -D -m 0644 redhat/varnish.logrotate %{buildroot}%{_sysconfdir}/logrotate.d/varnish +install -D -m 0755 redhat/varnish.initrc %{buildroot}%{_initrddir}/varnish +install -D -m 0755 redhat/varnishlog.initrc %{buildroot}%{_initrddir}/varnishlog +install -D -m 0755 redhat/varnishncsa.initrc %{buildroot}%{_initrddir}/varnishncsa +install -D -m 0755 redhat/varnish_reload_vcl %{buildroot}%{_bindir}/varnish_reload_vcl %clean rm -rf %{buildroot} @@ -174,7 +174,7 @@ rm -rf %{buildroot} %{_mandir}/man1/*.1* %{_mandir}/man3/*.3* %{_mandir}/man7/*.7* -%doc LICENSE README redhat/README.redhat ChangeLog +%doc INSTALL LICENSE README redhat/README.redhat ChangeLog %doc examples %dir %{_sysconfdir}/varnish/ %config(noreplace) %{_sysconfdir}/varnish/default.vcl From tfheen at varnish-cache.org Thu May 24 12:47:44 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:44 +0200 Subject: [3.0] ddb3bc3 No need to keep the sphinx doc =build dir. If a user wants them, she can recreate them. Message-ID: commit ddb3bc3dfb138e956bee83b76c56d99947751004 Author: Ingvar Hagelund Date: Mon Apr 23 11:17:57 2012 +0200 No need to keep the sphinx doc =build dir. If a user wants them, she can recreate them. diff --git a/redhat/varnish.spec b/redhat/varnish.spec index 484faf9..f25812a 100644 --- a/redhat/varnish.spec +++ b/redhat/varnish.spec @@ -119,7 +119,9 @@ tail -n +11 etc/default.vcl >> redhat/default.vcl redhat/varnish.initrc redhat/varnishlog.initrc redhat/varnishncsa.initrc %endif -cp -r doc/sphinx/\=build/html doc +rm -rf doc/sphinx/\=build/html/_sources +mv doc/sphinx/\=build/html doc +rm -rf doc/sphinx/\=build %check # rhel5 on ppc64 is just too strange From tfheen at varnish-cache.org Thu May 24 12:47:44 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:44 +0200 Subject: [3.0] 444e642 Add an explicit macro_undef() function so we don't pass a NULL argument to a printflike function. Message-ID: commit 444e642f78ddc3bccea79d7c7707c6f0517bdb69 Author: Poul-Henning Kamp Date: Mon Apr 23 11:35:56 2012 +0000 Add an explicit macro_undef() function so we don't pass a NULL argument to a printflike function. diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c index 53cbdcd..72caa2a 100644 --- a/bin/varnishtest/vtc.c +++ b/bin/varnishtest/vtc.c @@ -90,6 +90,8 @@ macro_def(struct vtclog *vl, const char *instance, const char *name, struct macro *m; va_list ap; + AN(fmt); + if (instance != NULL) { bprintf(buf1, "%s_%s", instance, name); name = buf1; @@ -99,23 +101,40 @@ macro_def(struct vtclog *vl, const char *instance, const char *name, VTAILQ_FOREACH(m, ¯o_list, list) if (!strcmp(name, m->name)) break; - if (m == NULL && fmt != NULL) { + if (m == NULL) { m = calloc(sizeof *m, 1); AN(m); REPLACE(m->name, name); VTAILQ_INSERT_TAIL(¯o_list, m, list); } - if (fmt != NULL) { - AN(m); - va_start(ap, fmt); - free(m->val); - m->val = NULL; - vbprintf(buf2, fmt, ap); - va_end(ap); - m->val = strdup(buf2); - AN(m->val); - vtc_log(vl, 4, "macro def %s=%s", name, m->val); - } else if (m != NULL) { + AN(m); + va_start(ap, fmt); + free(m->val); + m->val = NULL; + vbprintf(buf2, fmt, ap); + va_end(ap); + m->val = strdup(buf2); + AN(m->val); + vtc_log(vl, 4, "macro def %s=%s", name, m->val); + AZ(pthread_mutex_unlock(¯o_mtx)); +} + +void +macro_undef(struct vtclog *vl, const char *instance, const char *name) +{ + char buf1[256]; + struct macro *m; + + if (instance != NULL) { + bprintf(buf1, "%s_%s", instance, name); + name = buf1; + } + + AZ(pthread_mutex_lock(¯o_mtx)); + VTAILQ_FOREACH(m, ¯o_list, list) + if (!strcmp(name, m->name)) + break; + if (m != NULL) { vtc_log(vl, 4, "macro undef %s", name); VTAILQ_REMOVE(¯o_list, m, list); free(m->name); diff --git a/bin/varnishtest/vtc.h b/bin/varnishtest/vtc.h index 16861d3..2ee284f 100644 --- a/bin/varnishtest/vtc.h +++ b/bin/varnishtest/vtc.h @@ -80,6 +80,7 @@ void vtc_hexdump(struct vtclog *vl, int lvl, const char *pfx, int exec_file(const char *fn, const char *script, const char *tmpdir, char *logbuf, unsigned loglen); +void macro_undef(struct vtclog *vl, const char *instance, const char *name); void macro_def(struct vtclog *vl, const char *instance, const char *name, const char *fmt, ...); struct vsb *macro_expand(struct vtclog *vl, const char *text); diff --git a/bin/varnishtest/vtc_server.c b/bin/varnishtest/vtc_server.c index d1787b1..04a1bed 100644 --- a/bin/varnishtest/vtc_server.c +++ b/bin/varnishtest/vtc_server.c @@ -147,9 +147,9 @@ server_delete(struct server *s) { CHECK_OBJ_NOTNULL(s, SERVER_MAGIC); - macro_def(s->vl, s->name, "addr", NULL); - macro_def(s->vl, s->name, "port", NULL); - macro_def(s->vl, s->name, "sock", NULL); + macro_undef(s->vl, s->name, "addr"); + macro_undef(s->vl, s->name, "port"); + macro_undef(s->vl, s->name, "sock"); vtc_logclose(s->vl); free(s->name); /* XXX: MEMLEAK (?) (VSS ??) */ diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c index 1b3b445..e97fab2 100644 --- a/bin/varnishtest/vtc_varnish.c +++ b/bin/varnishtest/vtc_varnish.c @@ -527,9 +527,9 @@ varnish_stop(struct varnish *v) varnish_launch(v); if (vtc_error) return; - macro_def(v->vl, v->name, "addr", NULL); - macro_def(v->vl, v->name, "port", NULL); - macro_def(v->vl, v->name, "sock", NULL); + macro_undef(v->vl, v->name, "addr"); + macro_undef(v->vl, v->name, "port"); + macro_undef(v->vl, v->name, "sock"); vtc_log(v->vl, 2, "Stop"); (void)varnish_ask_cli(v, "stop", NULL); while (1) { From tfheen at varnish-cache.org Thu May 24 12:47:44 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:44 +0200 Subject: [3.0] 22bc7fc Also reflect the VCC exit code through if -C is specified. Message-ID: commit 22bc7fc6c47558e6e231ba922f183c601b79c620 Author: Poul-Henning Kamp Date: Mon Apr 23 16:17:14 2012 +0000 Also reflect the VCC exit code through if -C is specified. Fixes #1069 diff --git a/bin/varnishd/mgt_vcc.c b/bin/varnishd/mgt_vcc.c index 9e204bc..9638783 100644 --- a/bin/varnishd/mgt_vcc.c +++ b/bin/varnishd/mgt_vcc.c @@ -390,18 +390,16 @@ mgt_vcc_default(const char *b_arg, const char *f_arg, char *vcl, int C_flag) if (VSB_len(sb) > 0) fprintf(stderr, "%s", VSB_data(sb)); VSB_delete(sb); - if (C_flag) { - if (vf != NULL) - AZ(unlink(vf)); - return (0); - } + if (C_flag && vf != NULL) + AZ(unlink(vf)); if (vf == NULL) { fprintf(stderr, "\nVCL compilation failed\n"); return (1); + } else { + vp = mgt_vcc_add(buf, vf); + vp->active = 1; + return (0); } - vp = mgt_vcc_add(buf, vf); - vp->active = 1; - return (0); } /*--------------------------------------------------------------------*/ From tfheen at varnish-cache.org Thu May 24 12:47:44 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:44 +0200 Subject: [3.0] e441f59 Make it possible for Open/Net/DragonFly-BSD to find readline.h Message-ID: commit e441f5939a7d054801f72c77100253c44307890e Author: Poul-Henning Kamp Date: Thu Apr 26 16:10:17 2012 +0000 Make it possible for Open/Net/DragonFly-BSD to find readline.h diff --git a/bin/varnishadm/varnishadm.c b/bin/varnishadm/varnishadm.c index e67062f..043aa38 100644 --- a/bin/varnishadm/varnishadm.c +++ b/bin/varnishadm/varnishadm.c @@ -41,6 +41,8 @@ # include # ifdef HAVE_EDIT_READLINE_READLINE_H # include +# elif HAVE_READLINE_READLINE_H +# include # else # include # endif From tfheen at varnish-cache.org Thu May 24 12:47:44 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:44 +0200 Subject: [3.0] cbd5d1c Enable PCRE JIT-compiled regular expressions Message-ID: commit cbd5d1c4f30e537de3b38c138839c89f24ece324 Author: Dan McGee Date: Fri Dec 30 15:14:56 2011 -0600 Enable PCRE JIT-compiled regular expressions Implemented more or less as described in the pcrejit(3) manpage, and adds some compatibility defines for use with older pre-8.20 libraries that do not have this functionality. Fixes: #1080 diff --git a/lib/libvarnish/vre.c b/lib/libvarnish/vre.c index e11fa29..2d40f3f 100644 --- a/lib/libvarnish/vre.c +++ b/lib/libvarnish/vre.c @@ -36,9 +36,14 @@ struct vre { unsigned magic; #define VRE_MAGIC 0xe83097dc - pcre *re; + pcre *re; + pcre_extra *re_extra; }; +#ifndef PCRE_STUDY_JIT_COMPILE +#define PCRE_STUDY_JIT_COMPILE 0 +#endif + /* * We don't want to spread or even expose the majority of PCRE options * so we establish our own options and implement hard linkage to PCRE @@ -62,6 +67,20 @@ VRE_compile(const char *pattern, int options, VRE_free(&v); return (NULL); } + v->re_extra = pcre_study(v->re, PCRE_STUDY_JIT_COMPILE, errptr); + if (v->re_extra == NULL) { + if (*errptr != NULL) { + VRE_free(&v); + return (NULL); + } + /* allocate our own, pcre_study can return NULL without it + * being an error */ + v->re_extra = calloc(1, sizeof(pcre_extra)); + if (v->re_extra == NULL) { + VRE_free(&v); + return (NULL); + } + } return (v); } @@ -72,22 +91,23 @@ VRE_exec(const vre_t *code, const char *subject, int length, { CHECK_OBJ_NOTNULL(code, VRE_MAGIC); int ov[30]; - pcre_extra extra; if (ovector == NULL) { ovector = ov; ovecsize = sizeof(ov)/sizeof(ov[0]); } - memset(&extra, 0, sizeof extra); if (lim != NULL) { - extra.match_limit = lim->match; - extra.flags |= PCRE_EXTRA_MATCH_LIMIT; - extra.match_limit_recursion = lim->match_recursion; - extra.flags |= PCRE_EXTRA_MATCH_LIMIT_RECURSION; + code->re_extra->match_limit = lim->match; + code->re_extra->flags |= PCRE_EXTRA_MATCH_LIMIT; + code->re_extra->match_limit_recursion = lim->match_recursion; + code->re_extra->flags |= PCRE_EXTRA_MATCH_LIMIT_RECURSION; + } else { + code->re_extra->flags &= ~PCRE_EXTRA_MATCH_LIMIT; + code->re_extra->flags &= ~PCRE_EXTRA_MATCH_LIMIT_RECURSION; } - return (pcre_exec(code->re, &extra, subject, length, + return (pcre_exec(code->re, code->re_extra, subject, length, startoffset, options, ovector, ovecsize)); } @@ -98,6 +118,11 @@ VRE_free(vre_t **vv) *vv = NULL; CHECK_OBJ(v, VRE_MAGIC); +#ifdef PCRE_CONFIG_JIT + pcre_free_study(v->re_extra); +#else + free(v->re_extra); +#endif pcre_free(v->re); FREE_OBJ(v); } From tfheen at varnish-cache.org Thu May 24 12:47:44 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:44 +0200 Subject: [3.0] 68acd5b Add code coverage of the RST dumping code Message-ID: commit 68acd5b94fd130cae510dafb1726a7cc60a861b0 Author: Poul-Henning Kamp Date: Wed May 2 08:47:15 2012 +0000 Add code coverage of the RST dumping code diff --git a/bin/varnishtest/tests/a00009.vtc b/bin/varnishtest/tests/a00009.vtc index 4d35f85..f89231f 100644 --- a/bin/varnishtest/tests/a00009.vtc +++ b/bin/varnishtest/tests/a00009.vtc @@ -1,3 +1,4 @@ -varnishtest "See that the VCL compiler works" +varnishtest "Code coverage of VCL compiler and RSTdump" shell "cd ${topbuild}/bin/varnishd && ./varnishd -b 127.0.0.1:80 -C -n ${tmpdir} > /dev/null 2>&1" +shell "cd ${topbuild}/bin/varnishd && ./varnishd -x dumprst > /dev/null 2>&1" From tfheen at varnish-cache.org Thu May 24 12:47:45 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:45 +0200 Subject: [3.0] d6bc813 Fix ttl when backend fetches are salvaged into transient storage. Message-ID: commit d6bc813c8e08d7aaa20e27d52cf330d0548c7e9b Author: Poul-Henning Kamp Date: Mon May 21 07:23:27 2012 +0000 Fix ttl when backend fetches are salvaged into transient storage. Submitted by: Martin Fixes #1140 diff --git a/bin/varnishd/cache_center.c b/bin/varnishd/cache_center.c index bf08fb0..23183ed 100644 --- a/bin/varnishd/cache_center.c +++ b/bin/varnishd/cache_center.c @@ -788,12 +788,12 @@ cnt_fetchbody(struct sess *sp) * Try to salvage the transaction by allocating a * shortlived object on Transient storage. */ - sp->obj = STV_NewObject(sp, TRANSIENT_STORAGE, l, - &sp->wrk->exp, nhttp); if (sp->wrk->exp.ttl > params->shortlived) sp->wrk->exp.ttl = params->shortlived; sp->wrk->exp.grace = 0.0; sp->wrk->exp.keep = 0.0; + sp->obj = STV_NewObject(sp, TRANSIENT_STORAGE, l, + &sp->wrk->exp, nhttp); } if (sp->obj == NULL) { sp->err_code = 503; From tfheen at varnish-cache.org Thu May 24 12:51:10 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:10 +0200 Subject: [3.0] 302d463 Force lookup of kss resources and fix cached creation of objects in Plone Message-ID: commit 302d463c84cc5c6d0818db585bbb886bbd1c72cc Author: Cleber J Santos Date: Wed Jan 18 11:46:03 2012 -0200 Force lookup of kss resources and fix cached creation of objects in Plone diff --git a/etc/zope-plone.vcl b/etc/zope-plone.vcl index b69f583..263e343 100644 --- a/etc/zope-plone.vcl +++ b/etc/zope-plone.vcl @@ -52,13 +52,18 @@ sub vcl_recv { } return(lookup); } + + # Do not cache the creation of objects in Plone + if (req.url ~ "createObject"){ + return(pass); + } } # Don't cache authenticated requests if (req.http.Cookie && req.http.Cookie ~ "__ac(|_(name|password|persistent))=") { # Force lookup of specific urls unlikely to need protection - if (req.url ~ "\.(js|css)") { + if (req.url ~ "\.(js|css|kss)") { remove req.http.cookie; return(lookup); } From tfheen at varnish-cache.org Thu May 24 12:51:10 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:10 +0200 Subject: [3.0] b1d132c Don't try to stream when there is no body. Message-ID: commit b1d132c5e22ad37da0fc7c642373417052bbbe94 Author: Tollef Fog Heen Date: Wed May 23 13:28:30 2012 +0200 Don't try to stream when there is no body. diff --git a/bin/varnishd/cache_center.c b/bin/varnishd/cache_center.c index b3d7237..b2b9a45 100644 --- a/bin/varnishd/cache_center.c +++ b/bin/varnishd/cache_center.c @@ -747,6 +747,10 @@ cnt_fetchbody(struct sess *sp) if (!sp->wantbody) sp->wrk->do_stream = 0; + /* No reason to try streaming a non-existing body */ + if (sp->wrk->body_status == BS_NONE) + sp->wrk->do_stream = 0; + l = http_EstimateWS(sp->wrk->beresp, pass ? HTTPH_R_PASS : HTTPH_A_INS, &nhttp); From tfheen at varnish-cache.org Thu May 24 12:51:10 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:10 +0200 Subject: [3.0] b28e204 typo Message-ID: commit b28e20472e7ca46859781854caf4c9aa7a1c6481 Author: Lasse Karstensen Date: Mon Feb 6 14:29:39 2012 +0100 typo diff --git a/lib/libvcl/vcc_expr.c b/lib/libvcl/vcc_expr.c index 1f1c274..0c885c0 100644 --- a/lib/libvcl/vcc_expr.c +++ b/lib/libvcl/vcc_expr.c @@ -51,7 +51,7 @@ vcc_Type(enum var_type fmt) #include "vcc_types.h" #undef VCC_TYPE default: - assert("Unknwon Type"); + assert("Unknown Type"); return(NULL); } } From tfheen at varnish-cache.org Thu May 24 12:51:10 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:10 +0200 Subject: [3.0] a00d608 Allocate HTTP.status from http's designated workspace. Message-ID: commit a00d6085e6a25613ba97862c97bd3dc9bf1e7094 Author: Poul-Henning Kamp Date: Wed Feb 8 23:26:57 2012 +0000 Allocate HTTP.status from http's designated workspace. diff --git a/bin/varnishd/cache_http.c b/bin/varnishd/cache_http.c index 5ce1b6a..76b3f86 100644 --- a/bin/varnishd/cache_http.c +++ b/bin/varnishd/cache_http.c @@ -1078,7 +1078,7 @@ http_Write(struct worker *w, const struct http *hp, int resp) l = WRW_WriteH(w, &hp->hd[HTTP_HDR_PROTO], " "); WSLH(w, fd, hp, HTTP_HDR_PROTO); - hp->hd[HTTP_HDR_STATUS].b = WS_Alloc(w->ws, 4); + hp->hd[HTTP_HDR_STATUS].b = WS_Alloc(hp->ws, 4); AN(hp->hd[HTTP_HDR_STATUS].b); sprintf(hp->hd[HTTP_HDR_STATUS].b, "%3d", hp->status); From tfheen at varnish-cache.org Thu May 24 12:51:10 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:10 +0200 Subject: [3.0] 6590e65 Most of these variables are not available in vcl_deliver Message-ID: commit 6590e6561996f0d9c9cd99178b3b936899dcc918 Author: Andreas Plesner Jacobsen Date: Thu Feb 16 19:53:59 2012 +0100 Most of these variables are not available in vcl_deliver Fixes #1056 diff --git a/doc/sphinx/reference/vcl.rst b/doc/sphinx/reference/vcl.rst index 5d3030f..ff92c56 100644 --- a/doc/sphinx/reference/vcl.rst +++ b/doc/sphinx/reference/vcl.rst @@ -836,7 +836,8 @@ beresp.storage After the object is entered into the cache, the following (mostly read-only) variables are available when the object has been located in -cache, typically in vcl_hit and vcl_deliver. +cache, typically in vcl_hit, or when constructing a synthetic reply in +vcl_error: obj.proto The HTTP protocol version used when the object was retrieved. @@ -852,11 +853,12 @@ obj.ttl obj.lastuse The approximate time elapsed since the object was last requests, in - seconds. + seconds. This variable is also available in vcl_deliver. obj.hits The approximate number of times the object has been delivered. A value - of 0 indicates a cache miss. + of 0 indicates a cache miss. This variable is also available in + vcl_deliver. obj.grace The object's grace period in seconds. obj.grace is writable. From tfheen at varnish-cache.org Thu May 24 12:51:10 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:10 +0200 Subject: [3.0] c987fa8 Add more info about changes from 2.1 to 3.0. Thanks to xcir.net for inspiration. Message-ID: commit c987fa8798760b5be55060264d54b9a5b9f30850 Author: Andreas Plesner Jacobsen Date: Fri Feb 24 12:16:25 2012 +0100 Add more info about changes from 2.1 to 3.0. Thanks to xcir.net for inspiration. diff --git a/doc/sphinx/installation/upgrade.rst b/doc/sphinx/installation/upgrade.rst index 0ed4f9f..cee17b8 100644 --- a/doc/sphinx/installation/upgrade.rst +++ b/doc/sphinx/installation/upgrade.rst @@ -60,10 +60,10 @@ becomes:: } } -``beresp.cacheable`` is gone -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``beresp.cacheable`` and ``obj.cacheable``is gone +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -``beresp.cacheable`` is gone, and can be replaced with ``beresp.ttl > 0s`` +``beresp.cacheable`` is gone, and can be replaced with ``beresp.ttl > 0s``. Similarly ``obj.cacheable`` can be replaced with ``obj.ttl > 0s``. returns are now done with the ``return()`` function ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -111,6 +111,56 @@ The difference in behaviour of ``pass`` in ``vcl_recv`` and different, you must now do ``return(hit_for_pass)`` when doing a pass in ``vcl_fetch``. +Changes to runtime parameters +============================= + +Deleted parameters +~~~~~~~~~~~~~~~~~~ + +``cache_vbe_conns`` and ``err_ttl`` has been removed. + +New parameters +~~~~~~~~~~~~~~ + +The following parameters have been added, see man varnishd for reference: +* ``default_keep`` +* ``expiry_sleep`` +* ``fetch_maxchunksize`` +* ``gzip_level`` +* ``gzip_memlevel`` +* ``gzip_stack_buffer`` +* ``gzip_tmp_space`` +* ``gzip_window`` +* ``http_gzip_support`` +* ``http_req_hdr_len`` +* ``http_req_size`` +* ``http_resp_hdr_len`` +* ``http_resp_size`` +* ``shortlived`` +* ``thread_pool_workspace`` +* ``vcc_err_unref`` +* ``vcl_dir`` +* ``vmod_dir`` + +Changed default values +~~~~~~~~~~~~~~~~~~~~~~ + +The following parameters have new defaults: + +* ``ban_lurker_sleep`` changed from 0 to 0.01 seconds, enabling the ban lurker by default. +* ``connect_timeout`` changed from 0.4 to 0.7 seconds. +* ``log_hashstring`` changed from off to on. +* ``send_timeout`` changed from 60 to 60 seconds. +* ``thread_pool_add_delay`` changed from 20 to 2 ms. + +Changed parameter names +~~~~~~~~~~~~~~~~~~~~~~~ + +The following parameters have new names: +* ``http_headers`` has been renamed to ``http_max_hdr``. +* ``max_esi_includes`` has been renamed to ``max_esi_depth``. +* ``overflow_max`` has been renamed to ``queue_max``. +* ``purge_dups`` has been renamed to ``ban_dups``. Changes to behaviour ==================== From tfheen at varnish-cache.org Thu May 24 12:51:10 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:10 +0200 Subject: [3.0] a636c01 Detect client crashing during startup Message-ID: commit a636c010cbb767a4610d8d6b11f97e15d027bbce Author: Poul-Henning Kamp Date: Sun Feb 19 11:05:09 2012 +0000 Detect client crashing during startup diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c index dec9754..1b3b445 100644 --- a/bin/varnishtest/vtc_varnish.c +++ b/bin/varnishtest/vtc_varnish.c @@ -159,6 +159,12 @@ wait_running(const struct varnish *v) if (st != CLIS_OK) vtc_log(v->vl, 0, "CLI status command failed: %u %s", st, r); + if (!strcmp(r, "Child in state stopped")) { + vtc_log(v->vl, 0, + "Child stopped before running: %u %s", st, r); + free(r); + break; + } if (!strcmp(r, "Child in state running")) { free(r); break; From tfheen at varnish-cache.org Thu May 24 12:51:10 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:10 +0200 Subject: [3.0] 7160b84 Grammar Message-ID: commit 7160b841a89bfc39ec4d19fbace5ecbc9af26e28 Author: Andreas Plesner Jacobsen Date: Fri Feb 24 14:52:38 2012 +0100 Grammar diff --git a/doc/sphinx/installation/upgrade.rst b/doc/sphinx/installation/upgrade.rst index 2402af0..2c06a3f 100644 --- a/doc/sphinx/installation/upgrade.rst +++ b/doc/sphinx/installation/upgrade.rst @@ -60,8 +60,8 @@ becomes:: } } -``beresp.cacheable`` and ``obj.cacheable``is gone -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``beresp.cacheable`` and ``obj.cacheable`` are gone +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``beresp.cacheable`` is gone, and can be replaced with ``beresp.ttl > 0s``. Similarly ``obj.cacheable`` can be replaced with ``obj.ttl > 0s``. From tfheen at varnish-cache.org Thu May 24 12:51:10 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:10 +0200 Subject: [3.0] 9154117 Fix syntax Message-ID: commit 91541177ee3d9e3501a3ee701bd751d2ce305bfb Author: Andreas Plesner Jacobsen Date: Fri Feb 24 12:20:37 2012 +0100 Fix syntax diff --git a/doc/sphinx/installation/upgrade.rst b/doc/sphinx/installation/upgrade.rst index cee17b8..2402af0 100644 --- a/doc/sphinx/installation/upgrade.rst +++ b/doc/sphinx/installation/upgrade.rst @@ -123,6 +123,7 @@ New parameters ~~~~~~~~~~~~~~ The following parameters have been added, see man varnishd for reference: + * ``default_keep`` * ``expiry_sleep`` * ``fetch_maxchunksize`` @@ -157,6 +158,7 @@ Changed parameter names ~~~~~~~~~~~~~~~~~~~~~~~ The following parameters have new names: + * ``http_headers`` has been renamed to ``http_max_hdr``. * ``max_esi_includes`` has been renamed to ``max_esi_depth``. * ``overflow_max`` has been renamed to ``queue_max``. From tfheen at varnish-cache.org Thu May 24 12:51:10 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:10 +0200 Subject: [3.0] fdd168f Add short example on how to get Websockets to work Message-ID: commit fdd168f95e2bfa0ae2d6aebaec2124b4cb856f6c Author: Lasse Karstensen Date: Fri Feb 24 15:12:44 2012 +0100 Add short example on how to get Websockets to work diff --git a/doc/sphinx/tutorial/websockets.rst b/doc/sphinx/tutorial/websockets.rst new file mode 100644 index 0000000..a74353e --- /dev/null +++ b/doc/sphinx/tutorial/websockets.rst @@ -0,0 +1,20 @@ + +Using Websockets +---------------- + +Websockets is a technology for creating a bidirectional stream-based channel over HTTP. + +To run websockets through Varnish you need to pipe it, and copy the Upgrade header. Use the following +VCL config to do so:: + + sub vcl_pipe { + if (req.http.upgrade) { + set bereq.http.upgrade = req.http.upgrade; + } + } + sub vcl_recv { + if (req.http.Upgrade ~ "(?i)websocket") { + return (pipe); + } + } + From tfheen at varnish-cache.org Thu May 24 12:51:10 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:10 +0200 Subject: [3.0] 0358917 Add short example on how to get Websockets to work (#2) Message-ID: commit 0358917a6edaea5a4798a83e0a3dc0f6ca5b5ab8 Author: Lasse Karstensen Date: Fri Feb 24 15:14:12 2012 +0100 Add short example on how to get Websockets to work (#2) diff --git a/doc/sphinx/tutorial/index.rst b/doc/sphinx/tutorial/index.rst index c3a05f5..6769ec4 100644 --- a/doc/sphinx/tutorial/index.rst +++ b/doc/sphinx/tutorial/index.rst @@ -29,6 +29,7 @@ separate topic. Good luck. compression esi virtualised + websockets advanced_backend_servers handling_misbehaving_servers advanced_topics From tfheen at varnish-cache.org Thu May 24 12:51:10 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:10 +0200 Subject: [3.0] 0938a2e Drop the body of hit-for-pass objects once we have delivered them to the original requester. Message-ID: commit 0938a2ed1903a397d02640a60f4d977baf818267 Author: Poul-Henning Kamp Date: Mon Feb 27 08:31:41 2012 +0000 Drop the body of hit-for-pass objects once we have delivered them to the original requester. Submitted by: DocWilco diff --git a/bin/varnishd/cache_center.c b/bin/varnishd/cache_center.c index b2b9a45..bf08fb0 100644 --- a/bin/varnishd/cache_center.c +++ b/bin/varnishd/cache_center.c @@ -276,6 +276,13 @@ cnt_deliver(struct sess *sp) RES_WriteObj(sp); + /* No point in saving the body if it is hit-for-pass */ + if (sp->obj->objcore != NULL) { + CHECK_OBJ_NOTNULL(sp->obj->objcore, OBJCORE_MAGIC); + if (sp->obj->objcore->flags & OC_F_PASS) + STV_Freestore(sp->obj); + } + assert(WRW_IsReleased(sp->wrk)); assert(sp->wrk->wrw.ciov == sp->wrk->wrw.siov); (void)HSH_Deref(sp->wrk, NULL, &sp->obj); From tfheen at varnish-cache.org Thu May 24 12:51:10 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:10 +0200 Subject: [3.0] f262a57 Correct value for 2.1 Message-ID: commit f262a5714224dc585d1e217a9345e2604838859f Author: Andreas Plesner Jacobsen Date: Fri Feb 24 15:16:15 2012 +0100 Correct value for 2.1 diff --git a/doc/sphinx/installation/upgrade.rst b/doc/sphinx/installation/upgrade.rst index 2c06a3f..93446ea 100644 --- a/doc/sphinx/installation/upgrade.rst +++ b/doc/sphinx/installation/upgrade.rst @@ -151,7 +151,7 @@ The following parameters have new defaults: * ``ban_lurker_sleep`` changed from 0 to 0.01 seconds, enabling the ban lurker by default. * ``connect_timeout`` changed from 0.4 to 0.7 seconds. * ``log_hashstring`` changed from off to on. -* ``send_timeout`` changed from 60 to 60 seconds. +* ``send_timeout`` changed from 600 to 60 seconds. * ``thread_pool_add_delay`` changed from 20 to 2 ms. Changed parameter names From tfheen at varnish-cache.org Thu May 24 12:51:10 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:10 +0200 Subject: [3.0] 9528984 Avoid taking the saintmode lock if the list empty. Message-ID: commit 95289844b65349f15e9449cafc907ca7c2057451 Author: Poul-Henning Kamp Date: Mon Feb 27 08:47:12 2012 +0000 Avoid taking the saintmode lock if the list empty. Submitted by: DocWilco diff --git a/bin/varnishd/cache_backend.c b/bin/varnishd/cache_backend.c index 756d659..7e36bda 100644 --- a/bin/varnishd/cache_backend.c +++ b/bin/varnishd/cache_backend.c @@ -268,16 +268,15 @@ vbe_Healthy(const struct vdi_simple *vs, const struct sess *sp) /* VRT/VCC sets threshold to UINT_MAX to mark that it's not * specified by VCL (thus use param). */ - if (vs->vrt->saintmode_threshold == UINT_MAX) + threshold = vs->vrt->saintmode_threshold; + if (threshold == UINT_MAX) threshold = params->saintmode_threshold; - else - threshold = vs->vrt->saintmode_threshold; if (backend->admin_health == ah_healthy) threshold = UINT_MAX; - /* Saintmode is disabled */ - if (threshold == 0) + /* Saintmode is disabled, or list is empty */ + if (threshold == 0 || VTAILQ_EMPTY(&backend->troublelist)) return (1); if (sp->objcore == NULL) From tfheen at varnish-cache.org Thu May 24 12:51:10 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:10 +0200 Subject: [3.0] e7d1ca8 Use the hash digest as identification instead of the neutered objhead pointer, in order to not have dependency between trouble entry and objhead lifetime. Message-ID: commit e7d1ca8381c7451c10c79ac76d65588f08c011d4 Author: Poul-Henning Kamp Date: Mon Feb 27 12:41:33 2012 +0000 Use the hash digest as identification instead of the neutered objhead pointer, in order to not have dependency between trouble entry and objhead lifetime. Fixes #1091 diff --git a/bin/varnishd/cache_backend.c b/bin/varnishd/cache_backend.c index 7e36bda..c4b9a16 100644 --- a/bin/varnishd/cache_backend.c +++ b/bin/varnishd/cache_backend.c @@ -251,7 +251,6 @@ vbe_Healthy(const struct vdi_simple *vs, const struct sess *sp) unsigned i = 0, retval; unsigned int threshold; struct backend *backend; - uintptr_t target; double now; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); @@ -283,7 +282,6 @@ vbe_Healthy(const struct vdi_simple *vs, const struct sess *sp) return (1); now = sp->t_req; - target = (uintptr_t)(sp->objcore->objhead); old = NULL; retval = 1; @@ -298,7 +296,7 @@ vbe_Healthy(const struct vdi_simple *vs, const struct sess *sp) break; } - if (tr->target == target) { + if (!memcmp(tr->digest, sp->digest, sizeof tr->digest)) { retval = 0; break; } diff --git a/bin/varnishd/cache_backend.h b/bin/varnishd/cache_backend.h index 059b4e7..b16d51e 100644 --- a/bin/varnishd/cache_backend.h +++ b/bin/varnishd/cache_backend.h @@ -97,7 +97,7 @@ struct director { struct trouble { unsigned magic; #define TROUBLE_MAGIC 0x4211ab21 - uintptr_t target; + unsigned char digest[DIGEST_LEN]; double timeout; VTAILQ_ENTRY(trouble) list; }; diff --git a/bin/varnishd/cache_vrt_var.c b/bin/varnishd/cache_vrt_var.c index 2054953..9a2e500 100644 --- a/bin/varnishd/cache_vrt_var.c +++ b/bin/varnishd/cache_vrt_var.c @@ -149,7 +149,7 @@ VRT_l_beresp_saintmode(const struct sess *sp, double a) ALLOC_OBJ(new, TROUBLE_MAGIC); AN(new); - new->target = (uintptr_t)(sp->objcore->objhead); + memcpy(new->digest, sp->digest, sizeof new->digest); new->timeout = sp->t_req + a; /* Insert the new item on the list before the first item with a diff --git a/bin/varnishtest/tests/r01091.vtc b/bin/varnishtest/tests/r01091.vtc new file mode 100644 index 0000000..9234ffc --- /dev/null +++ b/bin/varnishtest/tests/r01091.vtc @@ -0,0 +1,36 @@ +varnishtest "Test fallback director with saint mode" + +server s1 { + rxreq + txresp -hdr "Foo: 1" + accept + rxreq + txresp -hdr "Foo: 1" +} -start + +server s2 { + rxreq + txresp -hdr "Foo: 2" -bodylen 1 +} -start + +varnish v1 -vcl+backend { + director f1 fallback { + { .backend = s1; } + { .backend = s2; } + } + sub vcl_recv { + set req.backend = f1; + } + sub vcl_fetch { + if(req.restarts < 1) { + set beresp.saintmode = 1h; + return(restart); + } + } +} -start + +client c1 { + txreq + rxresp + expect resp.http.foo == "2" +} -run From tfheen at varnish-cache.org Thu May 24 12:51:10 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:10 +0200 Subject: [3.0] d2e2591 backend cookies Message-ID: commit d2e259199d7f7a1a59f94eac9a283c23bd535fb9 Author: Per Buer Date: Wed Feb 29 16:17:09 2012 +0100 backend cookies diff --git a/doc/sphinx/tutorial/cookies.rst b/doc/sphinx/tutorial/cookies.rst index 0278712..20fd302 100644 --- a/doc/sphinx/tutorial/cookies.rst +++ b/doc/sphinx/tutorial/cookies.rst @@ -13,6 +13,9 @@ This can be overly conservative. A lot of sites use Google Analytics cookie is used by the client side javascript and is therefore of no interest to the server. +Cookies from the client +~~~~~~~~~~~~~~~~~~~~~~~ + For a lot of web application it makes sense to completely disregard the cookies unless you are accessing a special part of the web site. This VCL snippet in vcl_recv will disregard cookies unless you are @@ -63,3 +66,12 @@ cookies named COOKIE1 and COOKIE2 and you can marvel at it:: The example is taken from the Varnish Wiki, where you can find other scary examples of what can be done in VCL. + +Cookies coming from the backend +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +If your backend server sets a cookie using the Set-Cookie header +Varnish will not cache the page. A hit-for-pass object (see +:ref:`tutorial_vcl_fetch_actions`) is created. So, if the backend +server acts silly and sets unwanted cookies just unset the Set-Cookie +header and all should be fine. From tfheen at varnish-cache.org Thu May 24 12:51:10 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:10 +0200 Subject: [3.0] 36eb0b0 3.0 syntax Message-ID: commit 36eb0b093e4faa06367e301dd7fc0346f0e846d0 Author: Andreas Plesner Jacobsen Date: Sun Mar 4 16:48:45 2012 +0100 3.0 syntax diff --git a/doc/sphinx/tutorial/increasing_your_hitrate.rst b/doc/sphinx/tutorial/increasing_your_hitrate.rst index 83236d6..73d983e 100644 --- a/doc/sphinx/tutorial/increasing_your_hitrate.rst +++ b/doc/sphinx/tutorial/increasing_your_hitrate.rst @@ -146,7 +146,7 @@ header. You could easily add support for this header in VCL. In vcl_fetch:: if (beresp.http.Pragma ~ "nocache") { - pass; + return(pass); } Authorization From tfheen at varnish-cache.org Thu May 24 12:51:10 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:10 +0200 Subject: [3.0] 84cf8b1 Really change to 3.0 syntax Message-ID: commit 84cf8b1094ad1fa4fe3bcbabda20af99c49c2912 Author: Andreas Plesner Jacobsen Date: Sun Mar 4 16:51:38 2012 +0100 Really change to 3.0 syntax diff --git a/doc/sphinx/tutorial/increasing_your_hitrate.rst b/doc/sphinx/tutorial/increasing_your_hitrate.rst index 73d983e..b9fa7e6 100644 --- a/doc/sphinx/tutorial/increasing_your_hitrate.rst +++ b/doc/sphinx/tutorial/increasing_your_hitrate.rst @@ -146,7 +146,7 @@ header. You could easily add support for this header in VCL. In vcl_fetch:: if (beresp.http.Pragma ~ "nocache") { - return(pass); + return(hit_for_pass); } Authorization From tfheen at varnish-cache.org Thu May 24 12:51:10 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:10 +0200 Subject: [3.0] 68e7342 Grammar in varnishncsa man page Message-ID: commit 68e73421cf12ddb4a3ae8c8da362a65acd823b1d Author: Tollef Fog Heen Date: Wed Mar 7 14:18:24 2012 +0100 Grammar in varnishncsa man page diff --git a/doc/sphinx/reference/varnishncsa.rst b/doc/sphinx/reference/varnishncsa.rst index 9373f5c..2937b26 100644 --- a/doc/sphinx/reference/varnishncsa.rst +++ b/doc/sphinx/reference/varnishncsa.rst @@ -64,7 +64,7 @@ The following options are available: Defaults to 127.0.0.1 for backend requests. %{X}i - The contents of request header line X. + The contents of request header X. %l Remote logname (always '-') @@ -77,7 +77,7 @@ The following options are available: empty string. %{X}o - The contents of response header line X. + The contents of response header X. %r The first line of the request. Synthesized from other From tfheen at varnish-cache.org Thu May 24 12:51:10 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:10 +0200 Subject: [3.0] 2a5f37f Add section on device detection Message-ID: commit 2a5f37f415b4fdfc4103cb53c3b2c0c95818586f Author: Lasse Karstensen Date: Wed Mar 7 14:35:41 2012 +0100 Add section on device detection diff --git a/doc/sphinx/tutorial/devicedetection.rst b/doc/sphinx/tutorial/devicedetection.rst new file mode 100644 index 0000000..a083e6e --- /dev/null +++ b/doc/sphinx/tutorial/devicedetection.rst @@ -0,0 +1,260 @@ +.. _tutorial-devicedetect: + +Device detection +~~~~~~~~~~~~~~~~ + +Device detection is figuring out what kind of content to serve to a +client based on the User-Agent string supplied in a request. + +Use cases for this are for example to send size reduced files to mobile +clients with small screens and on high latency networks, or to +provide a streaming video codec that the client understands. + +There are a couple of strategies on what to do with such clients: +1) Redirect them to another URL. +2) Use a different backend for the special clients. +3) Change the backend requests so the usual backend sends tailored content. + +To make the examples easier to understand, it is assumed in this text +that all the req.http.X-UA-Device header is present and unique per client class +that content is to be served to. + +Setting this header can be as simple as:: + + sub vcl_recv {? + if (req.http.User-Agent ~ "(?i)iphone"?{ + set req.http.X-UA-Device = "mobile-iphone"; + } + } + +There are different commercial and free offerings in doing grouping and identifiying clients +in further detail than this. + + +Serve the different content on the same URL +------------------------------------------- + +The tricks involved are: +1. Detect the client (pretty simple, just include devicedetect.vcl and call +it) +2. Figure out how to signal the backend what client class this is. This +includes for example setting a header, changing a header or even changing the +backend request URL. +3. Modify any response from the backend to add missing Vary headers, so +Varnish' internal handling of this kicks in. +4. Modify output sent to the client so any caches outside our control don't +serve the wrong content. + +All this while still making sure that we only get 1 cache object per URL per +device class. + + +Example 1: Send HTTP header to backend +'''''''''''''''''''''''''''''''''''''' + +The basic case is that Varnish add the X-UA-Device HTTP header on the backend +requests, and the backend mentions in the response Vary header that the content +is dependant on this header. + +Everything works out of the box from Varnish' perspective. + +.. 071-example1-start +VCL:: + + sub vcl_recv { + # call some detection engine that set req.http.X-UA-Device + } + + sub append_ua_device { + if (req.http.X-UA-Device) { + set bereq.http.X-UA-Device = req.http.X-UA-Device; } + } + + # This must be done in vcl_miss and vcl_pass, before any backend request is + # actually sent. vcl_fetch runs after the request to the backend has + # completed. + sub vcl_miss { call append_ua_device; } + sub vcl_pass { call append_ua_device; } + + # so, this is a bit conterintuitive. The backend creates content based on + # the normalized User-Agent, but we use Vary on X-UA-Device so Varnish will + # use the same cached object for all U-As that map to the same X-UA-Device. + # + # If the backend does not mention in Vary that it has crafted special + # content based on the User-Agent (==X-UA-Device), add it. + # If your backend does set Vary: User-Agent, you may have to remove that here. + sub vcl_fetch { + if (req.http.X-UA-Device) { + if (!beresp.http.Vary) { # no Vary at all + set beresp.http.Vary = "X-UA-Device"; + } elseif (beresp.http.Vary !~ "X-UA-Device") { # add to existing Vary + set beresp.http.Vary = beresp.http.Vary + ", X-UA-Device"; + } + } + # comment this out if you don't want the client to know your + # classification + set beresp.http.X-UA-Device = req.http.X-UA-Device; + } + + # to keep any caches in the wild from serving wrong content to client #2 + # behind them, we need to transform the Vary on the way out. + sub vcl_deliver { + if ((req.http.X-UA-Device) && (resp.http.Vary)) { + set resp.http.Vary = regsub(resp.http.Vary, "X-UA-Device", "User-Agent"); + } + } +.. 071-example1-end + +Example 2: Normalize the User-Agent string +'''''''''''''''''''''''''''''''''''''''''' + +Another way of signaling the device type is to override or normalize the +User-Agent header sent to the backend. + +For example + + User-Agent: Mozilla/5.0 (Linux; U; Android 2.2; nb-no; HTC Desire Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 + +becomes: + + User-Agent: mobile-android + +when seen by the backend. + +This works if you don't need the original header for anything on the backend. +A possible use for this is for CGI scripts where only a small set of predefined +headers are (by default) available for the script. + +.. 072-example2-start +VCL:: + + sub vcl_recv { + # call some detection engine that set req.http.X-UA-Device + } + + # override the header before it is sent to the backend + sub vcl_miss { if (req.http.X-UA-Device) { set bereq.http.User-Agent = req.http.X-UA-Device; } } + sub vcl_pass { if (req.http.X-UA-Device) { set bereq.http.User-Agent = req.http.X-UA-Device; } } + + # standard Vary handling code from previous examples. + sub vcl_fetch { + if (req.http.X-UA-Device) { + if (!beresp.http.Vary) { # no Vary at all + set beresp.http.Vary = "X-UA-Device"; + } elseif (beresp.http.Vary !~ "X-UA-Device") { # add to existing Vary + set beresp.http.Vary = beresp.http.Vary + ", X-UA-Device"; + } + } + set beresp.http.X-UA-Device = req.http.X-UA-Device; + } + sub vcl_deliver { + if ((req.http.X-UA-Device) && (resp.http.Vary)) { + set resp.http.Vary = regsub(resp.http.Vary, "X-UA-Device", "User-Agent"); + } + } + +.. 072-example2-end + +Example 3: Add the device class as a GET query parameter +'''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +If everything else fails, you can add the device type as a GET argument. + + http://example.com/article/1234.html --> http://example.com/article/1234.html?devicetype=mobile-iphone + +The client itself does not see this classification, only the backend request +is changed. + +.. 073-example3-start +VCL:: + + sub vcl_recv { + # call some detection engine that set req.http.X-UA-Device + + if ((req.http.X-UA-Device) && (req.request == "GET")) { + # if there are existing GET arguments; + if (req.url ~ "\?") { + set req.http.X-get-devicetype = "&devicetype=" + req.http.X-UA-Device; + } else { + set req.http.X-get-devicetype = "?devicetype=" + req.http.X-UA-Device; + } + set req.url = req.url + req.http.X-get-devicetype; + unset req.http.X-get-devicetype; + } + } + + # Handle redirects, otherwise standard Vary handling code from previous + # examples. + sub vcl_fetch { + if (req.http.X-UA-Device) { + if (!beresp.http.Vary) { # no Vary at all + set beresp.http.Vary = "X-UA-Device"; + } elseif (beresp.http.Vary !~ "X-UA-Device") { # add to existing Vary + set beresp.http.Vary = beresp.http.Vary + ", X-UA-Device"; + } + + # if the backend returns a redirect (think missing trailing slash), + # we will potentially show the extra address to the client. we + # don't want that. if the backend reorders the get parameters, you + # may need to be smarter here. (? and & ordering) + + if (beresp.status == 301 || beresp.status == 302 || beresp.status == 303) { + set beresp.http.location = regsub(beresp.http.location, "[?&]devicetype=.*$", ""); + } + } + set beresp.http.X-UA-Device = req.http.X-UA-Device; + } + sub vcl_deliver { + if ((req.http.X-UA-Device) && (resp.http.Vary)) { + set resp.http.Vary = regsub(resp.http.Vary, "X-UA-Device", "User-Agent"); + } + } + +.. 073-example3-end + +Different backend for mobile clients +------------------------------------ + +If you have a different backend that serves pages for mobile clients, or any +special needs in VCL, you can use the X-UA-Device header like this:: + + backend mobile { + .host = "10.0.0.1"; + .port = "80"; + } + + sub vcl_recv { + # call some detection engine + + if (req.http.X-UA-Device ~ "^mobile" || req.http.X-UA-device ~ "^tablet") { + set req.backend = mobile; + } + } + +Redirecting mobile clients +-------------------------- + +If you want to redirect mobile clients you can use the following snippet. + +.. 065-redir-mobile-start +VCL:: + + sub vcl_recv { + # call some detection engine + + if (req.http.X-UA-Device ~ "^mobile" || req.http.X-UA-device ~ "^tablet") { + error 750 "Moved Temporarily"; + } + } + + sub vcl_error { + if (obj.status == 750) { + set obj.http.Location = "http://m.example.com" + req.url; + set obj.status = 302; + return(deliver); + } + } + +.. 065-redir-mobile-end + + diff --git a/doc/sphinx/tutorial/index.rst b/doc/sphinx/tutorial/index.rst index 6769ec4..d41bfbb 100644 --- a/doc/sphinx/tutorial/index.rst +++ b/doc/sphinx/tutorial/index.rst @@ -30,6 +30,7 @@ separate topic. Good luck. esi virtualised websockets + devicedetection advanced_backend_servers handling_misbehaving_servers advanced_topics From tfheen at varnish-cache.org Thu May 24 12:51:10 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:10 +0200 Subject: [3.0] 2efdcc3 Fixing a typo in the documentation. Message-ID: commit 2efdcc3884c822c6640372c5d7fafed8d6d1b85d Author: Derek Hammer Date: Thu Mar 8 03:11:26 2012 -0500 Fixing a typo in the documentation. diff --git a/doc/sphinx/tutorial/purging.rst b/doc/sphinx/tutorial/purging.rst index 5e5768e..22056a7 100644 --- a/doc/sphinx/tutorial/purging.rst +++ b/doc/sphinx/tutorial/purging.rst @@ -4,7 +4,7 @@ Purging and banning ===================== -One of the most effective way of increasing your hit ratio is to +One of the most effective ways of increasing your hit ratio is to increase the time-to-live (ttl) of your objects. But, as you're aware of, in this twitterific day of age serving content that is outdated is bad for business. From tfheen at varnish-cache.org Thu May 24 12:51:10 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:10 +0200 Subject: [3.0] 201bc8d Remove old Date: header before adding our new one. Message-ID: commit 201bc8d88a1f85f6caa97da94a8a6bf951afdbe2 Author: Poul-Henning Kamp Date: Fri Mar 9 09:58:41 2012 +0000 Remove old Date: header before adding our new one. Submitted by: scoof Fixes #1104 diff --git a/bin/varnishd/cache_response.c b/bin/varnishd/cache_response.c index 37459d7..5a0ee9e 100644 --- a/bin/varnishd/cache_response.c +++ b/bin/varnishd/cache_response.c @@ -133,6 +133,7 @@ RES_BuildHttp(const struct sess *sp) http_SetHeader(sp->wrk, sp->fd, sp->wrk->resp, "Transfer-Encoding: chunked"); + http_Unset(sp->wrk->resp, H_Date); TIM_format(TIM_real(), time_str); http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp, "Date: %s", time_str); From tfheen at varnish-cache.org Thu May 24 12:51:10 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:10 +0200 Subject: [3.0] 8a47021 Correct function name Message-ID: commit 8a47021105c231dd6d37ce643da2bd5feef6c816 Author: Andreas Plesner Jacobsen Date: Mon Mar 12 12:23:47 2012 +0100 Correct function name diff --git a/doc/sphinx/reference/vmod_std.rst b/doc/sphinx/reference/vmod_std.rst index 9c28a3c..a1ece16 100644 --- a/doc/sphinx/reference/vmod_std.rst +++ b/doc/sphinx/reference/vmod_std.rst @@ -50,7 +50,7 @@ Description Example set beresp.http.x-nice = std.tolower("VerY"); -set_up_tos +set_ip_tos ---------- Prototype set_ip_tos(INT i) From tfheen at varnish-cache.org Thu May 24 12:51:10 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:10 +0200 Subject: [3.0] 527376f Small doc fixes Message-ID: commit 527376f6515944300b6e47e06d7efe8f1d397367 Author: Andreas Plesner Jacobsen Date: Mon Mar 12 12:25:41 2012 +0100 Small doc fixes diff --git a/doc/sphinx/tutorial/logging.rst b/doc/sphinx/tutorial/logging.rst index 68f1d87..1f0bc18 100644 --- a/doc/sphinx/tutorial/logging.rst +++ b/doc/sphinx/tutorial/logging.rst @@ -9,7 +9,7 @@ memory segment. When the end of the segment is reached we start over, overwriting old data. This is much, much faster then logging to a file and it doesn't require disk space. -The flip side is that if you forget to have program actually write the +The flip side is that if you forget to have a program actually write the logs to disk they will disappear. varnishlog is one of the programs you can use to look at what Varnish diff --git a/doc/sphinx/tutorial/vcl.rst b/doc/sphinx/tutorial/vcl.rst index 7171ab6..54bce37 100644 --- a/doc/sphinx/tutorial/vcl.rst +++ b/doc/sphinx/tutorial/vcl.rst @@ -135,7 +135,7 @@ down for, uhm, examples. Example 1 - manipulating headers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Lets say we want to remove the cookie for all objects in the /static +Lets say we want to remove the cookie for all objects in the /images directory of our web server:: sub vcl_recv { From tfheen at varnish-cache.org Thu May 24 12:51:11 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:11 +0200 Subject: [3.0] e2d35b4 Fix for #1109 Message-ID: commit e2d35b4a3c514acf4d5bdf5cdba86682783475b1 Author: Poul-Henning Kamp Date: Tue Apr 10 12:03:16 2012 +0000 Fix for #1109 I've opted for a less intrusive fix that Martin proposed, but my fix is largely a rework of his suggested patch. Testcase by: Martin diff --git a/bin/varnishd/cache_esi_deliver.c b/bin/varnishd/cache_esi_deliver.c index cc3f569..bdb4357 100644 --- a/bin/varnishd/cache_esi_deliver.c +++ b/bin/varnishd/cache_esi_deliver.c @@ -440,12 +440,10 @@ ved_deliver_byterange(const struct sess *sp, ssize_t low, ssize_t high) ssize_t l, lx; u_char *p; -//printf("BR %jd %jd\n", low, high); lx = 0; VTAILQ_FOREACH(st, &sp->obj->store, list) { p = st->ptr; l = st->len; -//printf("[0-] %jd %jd\n", lx, lx + l); if (lx + l < low) { lx += l; continue; @@ -458,16 +456,14 @@ ved_deliver_byterange(const struct sess *sp, ssize_t low, ssize_t high) l -= (low - lx); lx = low; } -//printf("[1-] %jd %jd\n", lx, lx + l); if (lx + l >= high) l = high - lx; -//printf("[2-] %jd %jd\n", lx, lx + l); assert(lx >= low && lx + l <= high); if (l != 0) (void)WRW_Write(sp->wrk, p, l); - if (lx + st->len > high) + if (p + l < st->ptr + st->len) return(p[l]); - lx += st->len; + lx += l; } INCOMPL(); } @@ -478,10 +474,12 @@ ESI_DeliverChild(const struct sess *sp) struct storage *st; struct object *obj; ssize_t start, last, stop, lpad; - u_char *p, cc; + u_char cc; uint32_t icrc; uint32_t ilen; uint8_t *dbits; + int i, j; + uint8_t tailbuf[8]; if (!sp->obj->gziped) { VTAILQ_FOREACH(st, &sp->obj->store, list) @@ -561,12 +559,21 @@ ESI_DeliverChild(const struct sess *sp) } if (lpad > 0) (void)WRW_Write(sp->wrk, dbits + 1, lpad); + + /* We need the entire tail, but it may not be in one storage segment */ st = VTAILQ_LAST(&sp->obj->store, storagehead); - assert(st->len > 8); + for (i = sizeof tailbuf; i > 0; i -= j) { + j = st->len; + if (j > i) + j = i; + memcpy(tailbuf + i - j, st->ptr + st->len - j, j); + st = VTAILQ_PREV(st, storagehead, list); + assert(i == j || st != NULL); + } + + icrc = vle32dec(tailbuf); + ilen = vle32dec(tailbuf + 4); - p = st->ptr + st->len - 8; - icrc = vle32dec(p); - ilen = vle32dec(p + 4); sp->wrk->crc = crc32_combine(sp->wrk->crc, icrc, ilen); sp->wrk->l_crc += ilen; } diff --git a/bin/varnishtest/tests/r01109.vtc b/bin/varnishtest/tests/r01109.vtc new file mode 100644 index 0000000..50f0a0e --- /dev/null +++ b/bin/varnishtest/tests/r01109.vtc @@ -0,0 +1,43 @@ +varnishtest "Test case for #1109 - Gzip+ESI broken for large included objects" + +server s1 { + rxreq + expect req.url == "/test1" + txresp -body {startend} + rxreq + expect req.url == "/include1" + # This tests ESI+gzip delivery when the ESI-included object + # has more than one storage chunk + txresp -bodylen 4082 + + rxreq + txresp -body {startend} + expect req.url == "/test2" + + rxreq + expect req.url == "/include2" + # This tests gzip trailer extraction for ESI+gzip CRC calculation + # when the trailer spans two storage chunks + txresp -bodylen 4074 +} -start + +varnish v1 -arg "-pfetch_chunksize=4k" -arg "-pgzip_level=0" -vcl+backend { + sub vcl_fetch { + if (req.url ~ "/test") { + set beresp.do_esi = true; + } + set beresp.do_gzip = true; + } +} -start + +client c1 { + txreq -url "/test1" -hdr "Accept-Encoding: gzip" + rxresp + gunzip + expect resp.bodylen == 4096 + + txreq -url "/test2" -hdr "Accept-Encoding: gzip" + rxresp + gunzip + expect resp.bodylen == 4088 +} -run From tfheen at varnish-cache.org Thu May 24 12:51:11 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:11 +0200 Subject: [3.0] d499461 Stopgap fix to get FreeBSD 10-current compiling again. Message-ID: commit d499461fbe28d513211e6694ea22de88eb6e88a0 Author: Poul-Henning Kamp Date: Thu Apr 12 07:24:02 2012 +0000 Stopgap fix to get FreeBSD 10-current compiling again. diff --git a/bin/varnishadm/varnishadm.c b/bin/varnishadm/varnishadm.c index 68ebbf7..e67062f 100644 --- a/bin/varnishadm/varnishadm.c +++ b/bin/varnishadm/varnishadm.c @@ -38,7 +38,12 @@ #include #ifdef HAVE_LIBEDIT -#include +# include +# ifdef HAVE_EDIT_READLINE_READLINE_H +# include +# else +# include +# endif #endif #include "vcli.h" diff --git a/configure.ac b/configure.ac index 55b2281..0fbb620 100644 --- a/configure.ac +++ b/configure.ac @@ -150,6 +150,7 @@ AC_SUBST(PCRE_LIBS) PKG_CHECK_MODULES([LIBEDIT], [libedit], [AC_DEFINE([HAVE_LIBEDIT], [1], [Define we have libedit])], [AC_CHECK_HEADERS([readline/readline.h]) + AC_CHECK_HEADERS([edit/readline/readline.h]) AC_CHECK_LIB(edit, el_init, [ AC_DEFINE([HAVE_LIBEDIT], [1], [Define we have libedit]) LIBEDIT_CFLAGS="" From tfheen at varnish-cache.org Thu May 24 12:51:11 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:11 +0200 Subject: [3.0] b97fc0c Fix #1126 by properly setting the mask token to the IP number token. Message-ID: commit b97fc0cd048eb92ca7ad4f25b91e34837c5e1508 Author: Poul-Henning Kamp Date: Mon Apr 16 07:04:40 2012 +0000 Fix #1126 by properly setting the mask token to the IP number token. Varnishtest doesn't see the difference between a VCC core dump and a VCC error, so a test-case is non-trivial. Fixes #1126 diff --git a/lib/libvcl/vcc_acl.c b/lib/libvcl/vcc_acl.c index 30c9eea..272f3c6 100644 --- a/lib/libvcl/vcc_acl.c +++ b/lib/libvcl/vcc_acl.c @@ -265,8 +265,10 @@ vcc_acl_try_netnotation(struct vcc *tl, struct acl_e *ae) return (0); p += k + 1; } - if (ae->t_mask == NULL) + if (ae->t_mask == NULL) { ae->mask = 8 + 8 * i; + ae->t_mask = ae->t_addr; + } vcc_acl_add_entry(tl, ae, 4, b, AF_INET); return (1); } From tfheen at varnish-cache.org Thu May 24 12:51:11 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:11 +0200 Subject: [3.0] cbd31d0 Fix escaping in regsub docs Message-ID: commit cbd31d0e3987608bdb842fc97664ef13e755e4ea Author: Tollef Fog Heen Date: Mon Apr 16 14:11:30 2012 +0200 Fix escaping in regsub docs diff --git a/doc/sphinx/reference/vcl.rst b/doc/sphinx/reference/vcl.rst index 212cd2b..927f640 100644 --- a/doc/sphinx/reference/vcl.rst +++ b/doc/sphinx/reference/vcl.rst @@ -420,9 +420,9 @@ hash_data(str) regsub(str, regex, sub) Returns a copy of str with the first occurrence of the regular - expression regex replaced with sub. Within sub, \\0 (which can - also be spelled &) is replaced with the entire matched string, - and \n is replaced with the contents of subgroup n in the + expression regex replaced with sub. Within sub, \\0 (which can + also be spelled \\&) is replaced with the entire matched string, + and \\n is replaced with the contents of subgroup n in the matched string. regsuball(str, regex, sub) From tfheen at varnish-cache.org Thu May 24 12:51:11 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:11 +0200 Subject: [3.0] 9d649d9 Expose resp.body for inspection and testing in varnishtest Message-ID: commit 9d649d9a7f7969d3e712bfe1f4db55aa9b33d549 Author: Martin Blix Grydeland Date: Tue Mar 27 14:12:33 2012 +0200 Expose resp.body for inspection and testing in varnishtest Needed to test #1123 diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c index 66e1d23..cb58704 100644 --- a/bin/varnishtest/vtc_http.c +++ b/bin/varnishtest/vtc_http.c @@ -196,6 +196,8 @@ cmd_var_resolve(struct http *hp, char *spec) return(hp->chunklen); if (!strcmp(spec, "resp.bodylen")) return(hp->bodylen); + if (!strcmp(spec, "resp.body")) + return(hp->body != NULL ? hp->body : spec); if (!memcmp(spec, "req.http.", 9)) { hh = hp->req; hdr = spec + 9; From tfheen at varnish-cache.org Thu May 24 12:51:11 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:11 +0200 Subject: [3.0] d92617a Removed source installation instructions INSTALL, as requested by rpmlint Message-ID: commit d92617aff2e2ebeb99ebbc052ca27c649720000b Author: Ingvar Hagelund Date: Mon Apr 23 10:52:40 2012 +0200 Removed source installation instructions INSTALL, as requested by rpmlint diff --git a/redhat/varnish.spec b/redhat/varnish.spec index bde3705..484faf9 100644 --- a/redhat/varnish.spec +++ b/redhat/varnish.spec @@ -174,7 +174,7 @@ rm -rf %{buildroot} %{_mandir}/man1/*.1* %{_mandir}/man3/*.3* %{_mandir}/man7/*.7* -%doc INSTALL LICENSE README redhat/README.redhat ChangeLog +%doc LICENSE README redhat/README.redhat ChangeLog %doc examples %dir %{_sysconfdir}/varnish/ %config(noreplace) %{_sysconfdir}/varnish/default.vcl From tfheen at varnish-cache.org Thu May 24 12:51:11 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:11 +0200 Subject: [3.0] ddb3bc3 No need to keep the sphinx doc =build dir. If a user wants them, she can recreate them. Message-ID: commit ddb3bc3dfb138e956bee83b76c56d99947751004 Author: Ingvar Hagelund Date: Mon Apr 23 11:17:57 2012 +0200 No need to keep the sphinx doc =build dir. If a user wants them, she can recreate them. diff --git a/redhat/varnish.spec b/redhat/varnish.spec index 484faf9..f25812a 100644 --- a/redhat/varnish.spec +++ b/redhat/varnish.spec @@ -119,7 +119,9 @@ tail -n +11 etc/default.vcl >> redhat/default.vcl redhat/varnish.initrc redhat/varnishlog.initrc redhat/varnishncsa.initrc %endif -cp -r doc/sphinx/\=build/html doc +rm -rf doc/sphinx/\=build/html/_sources +mv doc/sphinx/\=build/html doc +rm -rf doc/sphinx/\=build %check # rhel5 on ppc64 is just too strange From tfheen at varnish-cache.org Thu May 24 12:51:12 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:12 +0200 Subject: [3.0] 22bc7fc Also reflect the VCC exit code through if -C is specified. Message-ID: commit 22bc7fc6c47558e6e231ba922f183c601b79c620 Author: Poul-Henning Kamp Date: Mon Apr 23 16:17:14 2012 +0000 Also reflect the VCC exit code through if -C is specified. Fixes #1069 diff --git a/bin/varnishd/mgt_vcc.c b/bin/varnishd/mgt_vcc.c index 9e204bc..9638783 100644 --- a/bin/varnishd/mgt_vcc.c +++ b/bin/varnishd/mgt_vcc.c @@ -390,18 +390,16 @@ mgt_vcc_default(const char *b_arg, const char *f_arg, char *vcl, int C_flag) if (VSB_len(sb) > 0) fprintf(stderr, "%s", VSB_data(sb)); VSB_delete(sb); - if (C_flag) { - if (vf != NULL) - AZ(unlink(vf)); - return (0); - } + if (C_flag && vf != NULL) + AZ(unlink(vf)); if (vf == NULL) { fprintf(stderr, "\nVCL compilation failed\n"); return (1); + } else { + vp = mgt_vcc_add(buf, vf); + vp->active = 1; + return (0); } - vp = mgt_vcc_add(buf, vf); - vp->active = 1; - return (0); } /*--------------------------------------------------------------------*/ From tfheen at varnish-cache.org Thu May 24 12:51:12 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:12 +0200 Subject: [3.0] e441f59 Make it possible for Open/Net/DragonFly-BSD to find readline.h Message-ID: commit e441f5939a7d054801f72c77100253c44307890e Author: Poul-Henning Kamp Date: Thu Apr 26 16:10:17 2012 +0000 Make it possible for Open/Net/DragonFly-BSD to find readline.h diff --git a/bin/varnishadm/varnishadm.c b/bin/varnishadm/varnishadm.c index e67062f..043aa38 100644 --- a/bin/varnishadm/varnishadm.c +++ b/bin/varnishadm/varnishadm.c @@ -41,6 +41,8 @@ # include # ifdef HAVE_EDIT_READLINE_READLINE_H # include +# elif HAVE_READLINE_READLINE_H +# include # else # include # endif From tfheen at varnish-cache.org Thu May 24 12:51:12 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:12 +0200 Subject: [3.0] 4dccc4f Be consistent about what environment we test the compiled VCL in. Message-ID: commit 4dccc4fbf7218b83dc62af21b269c98c5e6386c8 Author: Poul-Henning Kamp Date: Sat Apr 28 07:16:33 2012 +0000 Be consistent about what environment we test the compiled VCL in. diff --git a/bin/varnishd/mgt_vcc.c b/bin/varnishd/mgt_vcc.c index 9638783..b39c245 100644 --- a/bin/varnishd/mgt_vcc.c +++ b/bin/varnishd/mgt_vcc.c @@ -190,7 +190,9 @@ run_dlopen(void *priv) of = priv; - /* Try to load the object into the management process */ + mgt_sandbox(); + + /* Try to load the object into this sub-process */ if ((dlh = dlopen(of, RTLD_NOW | RTLD_LOCAL)) == NULL) { fprintf(stderr, "Compiled VCL program failed to load:\n %s\n", From tfheen at varnish-cache.org Thu May 24 12:51:12 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:12 +0200 Subject: [3.0] cbd5d1c Enable PCRE JIT-compiled regular expressions Message-ID: commit cbd5d1c4f30e537de3b38c138839c89f24ece324 Author: Dan McGee Date: Fri Dec 30 15:14:56 2011 -0600 Enable PCRE JIT-compiled regular expressions Implemented more or less as described in the pcrejit(3) manpage, and adds some compatibility defines for use with older pre-8.20 libraries that do not have this functionality. Fixes: #1080 diff --git a/lib/libvarnish/vre.c b/lib/libvarnish/vre.c index e11fa29..2d40f3f 100644 --- a/lib/libvarnish/vre.c +++ b/lib/libvarnish/vre.c @@ -36,9 +36,14 @@ struct vre { unsigned magic; #define VRE_MAGIC 0xe83097dc - pcre *re; + pcre *re; + pcre_extra *re_extra; }; +#ifndef PCRE_STUDY_JIT_COMPILE +#define PCRE_STUDY_JIT_COMPILE 0 +#endif + /* * We don't want to spread or even expose the majority of PCRE options * so we establish our own options and implement hard linkage to PCRE @@ -62,6 +67,20 @@ VRE_compile(const char *pattern, int options, VRE_free(&v); return (NULL); } + v->re_extra = pcre_study(v->re, PCRE_STUDY_JIT_COMPILE, errptr); + if (v->re_extra == NULL) { + if (*errptr != NULL) { + VRE_free(&v); + return (NULL); + } + /* allocate our own, pcre_study can return NULL without it + * being an error */ + v->re_extra = calloc(1, sizeof(pcre_extra)); + if (v->re_extra == NULL) { + VRE_free(&v); + return (NULL); + } + } return (v); } @@ -72,22 +91,23 @@ VRE_exec(const vre_t *code, const char *subject, int length, { CHECK_OBJ_NOTNULL(code, VRE_MAGIC); int ov[30]; - pcre_extra extra; if (ovector == NULL) { ovector = ov; ovecsize = sizeof(ov)/sizeof(ov[0]); } - memset(&extra, 0, sizeof extra); if (lim != NULL) { - extra.match_limit = lim->match; - extra.flags |= PCRE_EXTRA_MATCH_LIMIT; - extra.match_limit_recursion = lim->match_recursion; - extra.flags |= PCRE_EXTRA_MATCH_LIMIT_RECURSION; + code->re_extra->match_limit = lim->match; + code->re_extra->flags |= PCRE_EXTRA_MATCH_LIMIT; + code->re_extra->match_limit_recursion = lim->match_recursion; + code->re_extra->flags |= PCRE_EXTRA_MATCH_LIMIT_RECURSION; + } else { + code->re_extra->flags &= ~PCRE_EXTRA_MATCH_LIMIT; + code->re_extra->flags &= ~PCRE_EXTRA_MATCH_LIMIT_RECURSION; } - return (pcre_exec(code->re, &extra, subject, length, + return (pcre_exec(code->re, code->re_extra, subject, length, startoffset, options, ovector, ovecsize)); } @@ -98,6 +118,11 @@ VRE_free(vre_t **vv) *vv = NULL; CHECK_OBJ(v, VRE_MAGIC); +#ifdef PCRE_CONFIG_JIT + pcre_free_study(v->re_extra); +#else + free(v->re_extra); +#endif pcre_free(v->re); FREE_OBJ(v); } From tfheen at varnish-cache.org Thu May 24 12:51:12 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:12 +0200 Subject: [3.0] cf5076a These are not debug commands. Message-ID: commit cf5076a757cc6f81ac7844300f9f2dc58694290a Author: Poul-Henning Kamp Date: Thu May 10 08:57:47 2012 +0000 These are not debug commands. diff --git a/bin/varnishd/cache_backend_cfg.c b/bin/varnishd/cache_backend_cfg.c index 955ae26..47df12f 100644 --- a/bin/varnishd/cache_backend_cfg.c +++ b/bin/varnishd/cache_backend_cfg.c @@ -498,9 +498,9 @@ cli_backend_set_health(struct cli *cli, const char * const *av, void *priv) static struct cli_proto backend_cmds[] = { { "backend.list", "backend.list", - "\tList all backends\n", 0, 1, "d", cli_backend_list }, + "\tList all backends\n", 0, 1, "", cli_backend_list }, { "backend.set_health", "backend.set_health matcher state", - "\tShow a backend\n", 2, 2, "d", cli_backend_set_health }, + "\tShow a backend\n", 2, 2, "", cli_backend_set_health }, { NULL } }; From tfheen at varnish-cache.org Thu May 24 12:51:12 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:12 +0200 Subject: [3.0] 48ab7aa Req.hash_always_miss now implies req.hash_ignore_busy. Message-ID: commit 48ab7aa14ee48facf8fb0ccd74058c2e69ec0cb4 Author: Dag Haavi Finstad Date: Tue May 8 17:10:58 2012 +0200 Req.hash_always_miss now implies req.hash_ignore_busy. Fixes a case where we might get a cache hit even though hash_always_miss is set. Fixes: #1073 diff --git a/bin/varnishd/cache_hash.c b/bin/varnishd/cache_hash.c index 328964a..8da00a4 100644 --- a/bin/varnishd/cache_hash.c +++ b/bin/varnishd/cache_hash.c @@ -352,7 +352,7 @@ HSH_Lookup(struct sess *sp, struct objhead **poh) if (oc->flags & OC_F_BUSY) { CHECK_OBJ_NOTNULL(oc->busyobj, BUSYOBJ_MAGIC); - if (sp->hash_ignore_busy) + if (sp->hash_ignore_busy || sp->hash_always_miss) continue; if (oc->busyobj->vary != NULL && diff --git a/bin/varnishtest/tests/r01073.vtc b/bin/varnishtest/tests/r01073.vtc new file mode 100644 index 0000000..936f8ce --- /dev/null +++ b/bin/varnishtest/tests/r01073.vtc @@ -0,0 +1,55 @@ +varnishtest "Test that hash_always_miss also implies hash_ignore_busy. Ticket #1073." + +server s1 { + rxreq + sema r1 sync 2 + sema r2 sync 2 + delay 1 + txresp -hdr "Server: 1" +} -start + +server s2 { + rxreq + sema r2 sync 2 + txresp -hdr "Server: 2" +} -start + +varnish v1 -vcl+backend { + sub vcl_recv { + if (req.http.x-hash-always-miss == "1") { + set req.hash_always_miss = true; + } + if (req.http.x-client == "1") { + set req.backend = s1; + } + if (req.http.x-client == "2") { + set req.backend = s2; + } + } + sub vcl_deliver { + if(obj.hits > 0) { + set resp.http.X-Cache = "HIT"; + } else { + set resp.http.X-Cache = "MISS"; + } + } +} -start + +client c1 { + txreq -url "/" -hdr "x-client: 1" + rxresp + expect resp.status == 200 + expect resp.http.Server == "1" +} -start + +client c2 { + sema r1 sync 2 + txreq -url "/" -hdr "x-client: 2" -hdr "x-hash-always-miss: 1" + txreq -url "/" -hdr "x-client: 2" + rxresp + expect resp.status == 200 + expect resp.http.Server == "2" +} -start + +client c1 -wait +client c2 -wait From tfheen at varnish-cache.org Thu May 24 12:51:12 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:12 +0200 Subject: [3.0] 8015b1a Duration needs a unit Message-ID: commit 8015b1ab869a60cb220b5d20ef7b6d183cea64ab Author: Andreas Plesner Jacobsen Date: Thu May 24 14:17:52 2012 +0200 Duration needs a unit diff --git a/doc/sphinx/reference/vmod_std.rst b/doc/sphinx/reference/vmod_std.rst index a1ece16..984331e 100644 --- a/doc/sphinx/reference/vmod_std.rst +++ b/doc/sphinx/reference/vmod_std.rst @@ -124,7 +124,7 @@ Description the usual s (seconds), m (minutes), h (hours), d (days) and w (weeks) units. If *s* fails to parse, *fallback* will be used. Example - set beresp.ttl = std.duration("1w", 3600); + set beresp.ttl = std.duration("1w", 3600s); integer -------- From tfheen at varnish-cache.org Thu May 24 12:51:12 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:12 +0200 Subject: [3.0] dd0d586 Clean up docs about esi:remove and +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +The and constructs can be used to present +appropriate content whether or not ESI is available, for example you can +include content when ESI is available or link to it when it is not. +ESI processors will remove the start ("") when +the page is processed, while still processing the contents. If the page +is not processed, it will remain, becoming an HTML/XML comment tag. +ESI processors will remove tags and all content contained +in them, allowing you to only render the content when the page is not +being ESI-processed. +For example:: - - www.example.com + The license - -Example: -~~~~~~~~~~~~~~~~~~~~~~~~ - - -This is a special construct to allow HTML marked up with ESI to render -without processing. ESI Processors will remove the start ("") when the page is processed, while still processing the -contents. If the page is not processed, it will remain, becoming an -HTML/XML comment tag. For example:: - - -This assures that the ESI markup will not interfere with the rendering -of the final HTML if not processed. - - +

The full text of the license:

+ + --> From tfheen at varnish-cache.org Thu May 24 12:47:45 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:45 +0200 Subject: [3.0] e7b91c0 Verify range of port numbers before using them Message-ID: commit e7b91c0ad49132cffd449f7926027ee2c1e5524e Author: Kristian Lyngstol Date: Wed May 9 14:59:23 2012 +0200 Verify range of port numbers before using them Fixes #1035 diff --git a/bin/varnishtest/tests/r01035.vtc b/bin/varnishtest/tests/r01035.vtc new file mode 100644 index 0000000..ccd6078 --- /dev/null +++ b/bin/varnishtest/tests/r01035.vtc @@ -0,0 +1,8 @@ +varnishtest "Test case for #1035" + +varnish v1 -arg "-a 127.0.0.1:80 -b localhost:8080" +varnish v1 -cliok "param.set listen_address 127.0.0.1:80" +varnish v1 -clierr 106 "param.set listen_address 127.0.0.1:65540" +varnish v1 -clierr 106 "param.set listen_address 127.0.0.1:65536" +varnish v1 -clierr 106 "param.set listen_address 127.0.0.1:-1" +varnish v1 -cliok "param.set listen_address 127.0.0.1:65535" diff --git a/lib/libvarnish/vss.c b/lib/libvarnish/vss.c index 42b4db7..f902023 100644 --- a/lib/libvarnish/vss.c +++ b/lib/libvarnish/vss.c @@ -134,6 +134,7 @@ VSS_resolve(const char *addr, const char *port, struct vss_addr ***vap) struct addrinfo hints, *res0, *res; struct vss_addr **va; int i, ret; + long int ptst; char *adp, *hop; *vap = NULL; @@ -147,8 +148,12 @@ VSS_resolve(const char *addr, const char *port, struct vss_addr ***vap) if (adp == NULL) ret = getaddrinfo(addr, port, &hints, &res0); - else + else { + ptst = strtol(adp,NULL,10); + if (ptst < 0 || ptst > 65535) + return(0); ret = getaddrinfo(hop, adp, &hints, &res0); + } free(hop); free(adp); From tfheen at varnish-cache.org Thu May 24 12:51:12 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:12 +0200 Subject: [3.0] e7b91c0 Verify range of port numbers before using them Message-ID: commit e7b91c0ad49132cffd449f7926027ee2c1e5524e Author: Kristian Lyngstol Date: Wed May 9 14:59:23 2012 +0200 Verify range of port numbers before using them Fixes #1035 diff --git a/bin/varnishtest/tests/r01035.vtc b/bin/varnishtest/tests/r01035.vtc new file mode 100644 index 0000000..ccd6078 --- /dev/null +++ b/bin/varnishtest/tests/r01035.vtc @@ -0,0 +1,8 @@ +varnishtest "Test case for #1035" + +varnish v1 -arg "-a 127.0.0.1:80 -b localhost:8080" +varnish v1 -cliok "param.set listen_address 127.0.0.1:80" +varnish v1 -clierr 106 "param.set listen_address 127.0.0.1:65540" +varnish v1 -clierr 106 "param.set listen_address 127.0.0.1:65536" +varnish v1 -clierr 106 "param.set listen_address 127.0.0.1:-1" +varnish v1 -cliok "param.set listen_address 127.0.0.1:65535" diff --git a/lib/libvarnish/vss.c b/lib/libvarnish/vss.c index 42b4db7..f902023 100644 --- a/lib/libvarnish/vss.c +++ b/lib/libvarnish/vss.c @@ -134,6 +134,7 @@ VSS_resolve(const char *addr, const char *port, struct vss_addr ***vap) struct addrinfo hints, *res0, *res; struct vss_addr **va; int i, ret; + long int ptst; char *adp, *hop; *vap = NULL; @@ -147,8 +148,12 @@ VSS_resolve(const char *addr, const char *port, struct vss_addr ***vap) if (adp == NULL) ret = getaddrinfo(addr, port, &hints, &res0); - else + else { + ptst = strtol(adp,NULL,10); + if (ptst < 0 || ptst > 65535) + return(0); ret = getaddrinfo(hop, adp, &hints, &res0); + } free(hop); free(adp); From tfheen at varnish-cache.org Thu May 24 12:47:43 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:43 +0200 Subject: [3.0] 84cf8b1 Really change to 3.0 syntax Message-ID: commit 84cf8b1094ad1fa4fe3bcbabda20af99c49c2912 Author: Andreas Plesner Jacobsen Date: Sun Mar 4 16:51:38 2012 +0100 Really change to 3.0 syntax diff --git a/doc/sphinx/tutorial/increasing_your_hitrate.rst b/doc/sphinx/tutorial/increasing_your_hitrate.rst index 73d983e..b9fa7e6 100644 --- a/doc/sphinx/tutorial/increasing_your_hitrate.rst +++ b/doc/sphinx/tutorial/increasing_your_hitrate.rst @@ -146,7 +146,7 @@ header. You could easily add support for this header in VCL. In vcl_fetch:: if (beresp.http.Pragma ~ "nocache") { - return(pass); + return(hit_for_pass); } Authorization From tfheen at varnish-cache.org Thu May 24 12:51:11 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:11 +0200 Subject: [3.0] 48a0c44 Stopped using macros for make and install, according to Fedora's packaging guidelines Message-ID: commit 48a0c44775b86c2b2e19a08461ec3c1bd3869ba9 Author: Ingvar Hagelund Date: Mon Apr 23 10:43:20 2012 +0200 Stopped using macros for make and install, according to Fedora's packaging guidelines diff --git a/redhat/varnish.spec b/redhat/varnish.spec index 5ecb85f..6f6d71e 100644 --- a/redhat/varnish.spec +++ b/redhat/varnish.spec @@ -98,7 +98,7 @@ cp bin/varnishd/default.vcl etc/zope-plone.vcl examples #sed -i 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g; # s|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' libtool -%{__make} %{?_smp_mflags} +make %{?_smp_mflags} head -6 etc/default.vcl > redhat/default.vcl @@ -138,7 +138,7 @@ cp -r doc/sphinx/\=build/html doc %endif %endif -%{__make} check LD_LIBRARY_PATH="../../lib/libvarnish/.libs:../../lib/libvarnishcompat/.libs:../../lib/libvarnishapi/.libs:../../lib/libvcl/.libs:../../lib/libvgz/.libs" +make check LD_LIBRARY_PATH="../../lib/libvarnish/.libs:../../lib/libvarnishcompat/.libs:../../lib/libvarnishapi/.libs:../../lib/libvcl/.libs:../../lib/libvgz/.libs" %install rm -rf %{buildroot} From tfheen at varnish-cache.org Thu May 24 12:47:43 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:43 +0200 Subject: [3.0] e43966d escape \0 Message-ID: commit e43966d7c8516b6d5b49d4084cc38b4fbcdc56a0 Author: Per Buer Date: Wed Apr 4 10:17:01 2012 +0200 escape \0 diff --git a/doc/sphinx/reference/vcl.rst b/doc/sphinx/reference/vcl.rst index 01d783f..212cd2b 100644 --- a/doc/sphinx/reference/vcl.rst +++ b/doc/sphinx/reference/vcl.rst @@ -420,7 +420,7 @@ hash_data(str) regsub(str, regex, sub) Returns a copy of str with the first occurrence of the regular - expression regex replaced with sub. Within sub, \0 (which can + expression regex replaced with sub. Within sub, \\0 (which can also be spelled &) is replaced with the entire matched string, and \n is replaced with the contents of subgroup n in the matched string. From tfheen at varnish-cache.org Thu May 24 12:47:44 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:44 +0200 Subject: [3.0] 4dccc4f Be consistent about what environment we test the compiled VCL in. Message-ID: commit 4dccc4fbf7218b83dc62af21b269c98c5e6386c8 Author: Poul-Henning Kamp Date: Sat Apr 28 07:16:33 2012 +0000 Be consistent about what environment we test the compiled VCL in. diff --git a/bin/varnishd/mgt_vcc.c b/bin/varnishd/mgt_vcc.c index 9638783..b39c245 100644 --- a/bin/varnishd/mgt_vcc.c +++ b/bin/varnishd/mgt_vcc.c @@ -190,7 +190,9 @@ run_dlopen(void *priv) of = priv; - /* Try to load the object into the management process */ + mgt_sandbox(); + + /* Try to load the object into this sub-process */ if ((dlh = dlopen(of, RTLD_NOW | RTLD_LOCAL)) == NULL) { fprintf(stderr, "Compiled VCL program failed to load:\n %s\n", From tfheen at varnish-cache.org Thu May 24 12:51:12 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:12 +0200 Subject: [3.0] 3c0a6f0 Silence an annoying message when running varnishd -C Message-ID: commit 3c0a6f0bae5fd384ad4efca707746bcb243a5e30 Author: Poul-Henning Kamp Date: Sun Apr 29 18:22:08 2012 +0000 Silence an annoying message when running varnishd -C diff --git a/bin/varnishtest/tests/a00009.vtc b/bin/varnishtest/tests/a00009.vtc index 90569cc..4d35f85 100644 --- a/bin/varnishtest/tests/a00009.vtc +++ b/bin/varnishtest/tests/a00009.vtc @@ -1,3 +1,3 @@ varnishtest "See that the VCL compiler works" -shell "cd ${topbuild}/bin/varnishd && ./varnishd -b 127.0.0.1:80 -C -n ${tmpdir} > /dev/null" +shell "cd ${topbuild}/bin/varnishd && ./varnishd -b 127.0.0.1:80 -C -n ${tmpdir} > /dev/null 2>&1" From tfheen at varnish-cache.org Thu May 24 12:51:11 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:11 +0200 Subject: [3.0] 20396aa Include device class when hashing Message-ID: commit 20396aa7f50ca3c34ad601267b49828ebcc8bf5c Author: Lasse Karstensen Date: Mon Mar 12 16:13:56 2012 +0100 Include device class when hashing diff --git a/doc/sphinx/tutorial/devicedetection.rst b/doc/sphinx/tutorial/devicedetection.rst index abf729e..9f02493 100644 --- a/doc/sphinx/tutorial/devicedetection.rst +++ b/doc/sphinx/tutorial/devicedetection.rst @@ -228,6 +228,11 @@ special needs in VCL, you can use the X-UA-Device header like this:: set req.backend = mobile; } } + sub vcl_hash { + if (req.http.X-UA-Device) { + hash_data(req.http.X-UA-Device); + } + } Redirecting mobile clients -------------------------- From tfheen at varnish-cache.org Thu May 24 12:47:43 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:43 +0200 Subject: [3.0] 20396aa Include device class when hashing Message-ID: commit 20396aa7f50ca3c34ad601267b49828ebcc8bf5c Author: Lasse Karstensen Date: Mon Mar 12 16:13:56 2012 +0100 Include device class when hashing diff --git a/doc/sphinx/tutorial/devicedetection.rst b/doc/sphinx/tutorial/devicedetection.rst index abf729e..9f02493 100644 --- a/doc/sphinx/tutorial/devicedetection.rst +++ b/doc/sphinx/tutorial/devicedetection.rst @@ -228,6 +228,11 @@ special needs in VCL, you can use the X-UA-Device header like this:: set req.backend = mobile; } } + sub vcl_hash { + if (req.http.X-UA-Device) { + hash_data(req.http.X-UA-Device); + } + } Redirecting mobile clients -------------------------- From tfheen at varnish-cache.org Thu May 24 12:47:45 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:45 +0200 Subject: [3.0] cf5076a These are not debug commands. Message-ID: commit cf5076a757cc6f81ac7844300f9f2dc58694290a Author: Poul-Henning Kamp Date: Thu May 10 08:57:47 2012 +0000 These are not debug commands. diff --git a/bin/varnishd/cache_backend_cfg.c b/bin/varnishd/cache_backend_cfg.c index 955ae26..47df12f 100644 --- a/bin/varnishd/cache_backend_cfg.c +++ b/bin/varnishd/cache_backend_cfg.c @@ -498,9 +498,9 @@ cli_backend_set_health(struct cli *cli, const char * const *av, void *priv) static struct cli_proto backend_cmds[] = { { "backend.list", "backend.list", - "\tList all backends\n", 0, 1, "d", cli_backend_list }, + "\tList all backends\n", 0, 1, "", cli_backend_list }, { "backend.set_health", "backend.set_health matcher state", - "\tShow a backend\n", 2, 2, "d", cli_backend_set_health }, + "\tShow a backend\n", 2, 2, "", cli_backend_set_health }, { NULL } }; From tfheen at varnish-cache.org Thu May 24 12:51:12 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:12 +0200 Subject: [3.0] 79db58a Use admin health to control test-state Message-ID: commit 79db58ace109a60f5bc878ff99920fdef5c952fe Author: Poul-Henning Kamp Date: Thu May 10 09:09:49 2012 +0000 Use admin health to control test-state diff --git a/bin/varnishtest/tests/r00306.vtc b/bin/varnishtest/tests/r00306.vtc index ebc1774..079e994 100644 --- a/bin/varnishtest/tests/r00306.vtc +++ b/bin/varnishtest/tests/r00306.vtc @@ -23,10 +23,6 @@ varnish v1 -vcl { } backend s2 { .host = "${s2_addr}"; .port = "${s2_port}"; - .probe = { - .url = "/"; - .initial = 0; - } } director foo random { { .backend = s2; .weight = 1; } @@ -38,6 +34,9 @@ varnish v1 -vcl { } } -start +varnish v1 -cliok "backend.set_health s2 sick" +varnish v1 -cliok "backend.list" + client c1 { timeout 10 From tfheen at varnish-cache.org Thu May 24 12:47:44 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:44 +0200 Subject: [3.0] 09dedf3 Added missing changelog entries from fedora Message-ID: commit 09dedf3c42dd589dc9a0861ce78ef91dee94bb4c Author: Ingvar Hagelund Date: Mon Apr 23 13:13:03 2012 +0200 Added missing changelog entries from fedora diff --git a/redhat/varnish.spec b/redhat/varnish.spec index f25812a..144ace4 100644 --- a/redhat/varnish.spec +++ b/redhat/varnish.spec @@ -241,6 +241,22 @@ fi %postun libs -p /sbin/ldconfig %changelog +* Fri Feb 10 2012 Petr Pisar - 2.1.5-4 +- Rebuild against PCRE 8.30 + +* Sat Jan 14 2012 Fedora Release Engineering - 2.1.5-3 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild + +* Mon Feb 07 2011 Fedora Release Engineering - 2.1.5-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_15_Mass_Rebuild + +* Tue Feb 01 2011 Ingvar Hagelund - 2.1.5-1 +- New upstream release +- New download location +- Moved varnish_reload_vcl to sbin +- Removed patches included upstream +- Use jemalloc as system installed library + * Mon Nov 15 2010 Ingvar Hagelund - 3.0.0-0.svn20101115r5543 - Merged some changes from fedora - Upped general version to 3.0 prerelease in trunk From tfheen at varnish-cache.org Thu May 24 12:47:43 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:43 +0200 Subject: [3.0] cfdf155 typos, change example3 to allow for easier purging Message-ID: commit cfdf15518595603a49bf4bf4c550cbcf1b9fe07c Author: Lasse Karstensen Date: Thu Mar 8 14:26:27 2012 +0100 typos, change example3 to allow for easier purging diff --git a/doc/sphinx/tutorial/devicedetection.rst b/doc/sphinx/tutorial/devicedetection.rst index a083e6e..abf729e 100644 --- a/doc/sphinx/tutorial/devicedetection.rst +++ b/doc/sphinx/tutorial/devicedetection.rst @@ -27,8 +27,10 @@ Setting this header can be as simple as:: } } -There are different commercial and free offerings in doing grouping and identifiying clients -in further detail than this. +There are different commercial and free offerings in doing grouping and +identifiying clients in further detail than this. For a basic and community +based regular expression set, see +https://github.com/varnish/varnish-devicedetect/ . Serve the different content on the same URL @@ -45,14 +47,14 @@ Varnish' internal handling of this kicks in. 4. Modify output sent to the client so any caches outside our control don't serve the wrong content. -All this while still making sure that we only get 1 cache object per URL per +All this while still making sure that we only get 1 cached object per URL per device class. Example 1: Send HTTP header to backend '''''''''''''''''''''''''''''''''''''' -The basic case is that Varnish add the X-UA-Device HTTP header on the backend +The basic case is that Varnish adds the X-UA-Device HTTP header on the backend requests, and the backend mentions in the response Vary header that the content is dependant on this header. @@ -64,17 +66,7 @@ VCL:: sub vcl_recv { # call some detection engine that set req.http.X-UA-Device } - - sub append_ua_device { - if (req.http.X-UA-Device) { - set bereq.http.X-UA-Device = req.http.X-UA-Device; } - } - - # This must be done in vcl_miss and vcl_pass, before any backend request is - # actually sent. vcl_fetch runs after the request to the backend has - # completed. - sub vcl_miss { call append_ua_device; } - sub vcl_pass { call append_ua_device; } + # req.http.X-UA-Device is copied by Varnish into bereq.http.X-UA-Device # so, this is a bit conterintuitive. The backend creates content based on # the normalized User-Agent, but we use Vary on X-UA-Device so Varnish will @@ -170,7 +162,9 @@ VCL:: sub vcl_recv { # call some detection engine that set req.http.X-UA-Device + } + sub append_ua { if ((req.http.X-UA-Device) && (req.request == "GET")) { # if there are existing GET arguments; if (req.url ~ "\?") { @@ -183,6 +177,10 @@ VCL:: } } + # do this after vcl_hash, so all Vary-ants can be purged in one go. (avoid ban()ing) + sub vcl_miss { call append_ua; } + sub vcl_pass { call append_ua; } + # Handle redirects, otherwise standard Vary handling code from previous # examples. sub vcl_fetch { From tfheen at varnish-cache.org Thu May 24 12:51:11 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:11 +0200 Subject: [3.0] da6775e Fix libedit detection on *BSD OS's Message-ID: commit da6775ef0f4bbc474e2f74e2824743ee91d92f32 Author: Brad Date: Mon Jan 2 14:03:46 2012 -0500 Fix libedit detection on *BSD OS's The following patch allows the autoconf script to detect the presence of libedit when there isn't a pkg-config file present and thus allowing Varnish to detect libedit on OpenBSD/FreeBSD/NetBSD/DragonFly. Fixes: #1003 diff --git a/configure.ac b/configure.ac index 41ddf24..55b2281 100644 --- a/configure.ac +++ b/configure.ac @@ -149,7 +149,14 @@ AC_SUBST(PCRE_LIBS) PKG_CHECK_MODULES([LIBEDIT], [libedit], [AC_DEFINE([HAVE_LIBEDIT], [1], [Define we have libedit])], - [AC_MSG_WARN([libedit not found, disabling libedit support])]) + [AC_CHECK_HEADERS([readline/readline.h]) + AC_CHECK_LIB(edit, el_init, + [ AC_DEFINE([HAVE_LIBEDIT], [1], [Define we have libedit]) + LIBEDIT_CFLAGS="" + LIBEDIT_LIBS="-ledit ${CURSES_LIBS}" + ], + [AC_MSG_WARN([libedit not found, disabling libedit support])], + [${CURSES_LIBS}])]) # Checks for header files. AC_HEADER_STDC From tfheen at varnish-cache.org Thu May 24 12:47:45 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:45 +0200 Subject: [3.0] 48ab7aa Req.hash_always_miss now implies req.hash_ignore_busy. Message-ID: commit 48ab7aa14ee48facf8fb0ccd74058c2e69ec0cb4 Author: Dag Haavi Finstad Date: Tue May 8 17:10:58 2012 +0200 Req.hash_always_miss now implies req.hash_ignore_busy. Fixes a case where we might get a cache hit even though hash_always_miss is set. Fixes: #1073 diff --git a/bin/varnishd/cache_hash.c b/bin/varnishd/cache_hash.c index 328964a..8da00a4 100644 --- a/bin/varnishd/cache_hash.c +++ b/bin/varnishd/cache_hash.c @@ -352,7 +352,7 @@ HSH_Lookup(struct sess *sp, struct objhead **poh) if (oc->flags & OC_F_BUSY) { CHECK_OBJ_NOTNULL(oc->busyobj, BUSYOBJ_MAGIC); - if (sp->hash_ignore_busy) + if (sp->hash_ignore_busy || sp->hash_always_miss) continue; if (oc->busyobj->vary != NULL && diff --git a/bin/varnishtest/tests/r01073.vtc b/bin/varnishtest/tests/r01073.vtc new file mode 100644 index 0000000..936f8ce --- /dev/null +++ b/bin/varnishtest/tests/r01073.vtc @@ -0,0 +1,55 @@ +varnishtest "Test that hash_always_miss also implies hash_ignore_busy. Ticket #1073." + +server s1 { + rxreq + sema r1 sync 2 + sema r2 sync 2 + delay 1 + txresp -hdr "Server: 1" +} -start + +server s2 { + rxreq + sema r2 sync 2 + txresp -hdr "Server: 2" +} -start + +varnish v1 -vcl+backend { + sub vcl_recv { + if (req.http.x-hash-always-miss == "1") { + set req.hash_always_miss = true; + } + if (req.http.x-client == "1") { + set req.backend = s1; + } + if (req.http.x-client == "2") { + set req.backend = s2; + } + } + sub vcl_deliver { + if(obj.hits > 0) { + set resp.http.X-Cache = "HIT"; + } else { + set resp.http.X-Cache = "MISS"; + } + } +} -start + +client c1 { + txreq -url "/" -hdr "x-client: 1" + rxresp + expect resp.status == 200 + expect resp.http.Server == "1" +} -start + +client c2 { + sema r1 sync 2 + txreq -url "/" -hdr "x-client: 2" -hdr "x-hash-always-miss: 1" + txreq -url "/" -hdr "x-client: 2" + rxresp + expect resp.status == 200 + expect resp.http.Server == "2" +} -start + +client c1 -wait +client c2 -wait From tfheen at varnish-cache.org Thu May 24 12:47:44 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:44 +0200 Subject: [3.0] 3c0a6f0 Silence an annoying message when running varnishd -C Message-ID: commit 3c0a6f0bae5fd384ad4efca707746bcb243a5e30 Author: Poul-Henning Kamp Date: Sun Apr 29 18:22:08 2012 +0000 Silence an annoying message when running varnishd -C diff --git a/bin/varnishtest/tests/a00009.vtc b/bin/varnishtest/tests/a00009.vtc index 90569cc..4d35f85 100644 --- a/bin/varnishtest/tests/a00009.vtc +++ b/bin/varnishtest/tests/a00009.vtc @@ -1,3 +1,3 @@ varnishtest "See that the VCL compiler works" -shell "cd ${topbuild}/bin/varnishd && ./varnishd -b 127.0.0.1:80 -C -n ${tmpdir} > /dev/null" +shell "cd ${topbuild}/bin/varnishd && ./varnishd -b 127.0.0.1:80 -C -n ${tmpdir} > /dev/null 2>&1" From tfheen at varnish-cache.org Thu May 24 12:47:44 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:44 +0200 Subject: [3.0] 9d649d9 Expose resp.body for inspection and testing in varnishtest Message-ID: commit 9d649d9a7f7969d3e712bfe1f4db55aa9b33d549 Author: Martin Blix Grydeland Date: Tue Mar 27 14:12:33 2012 +0200 Expose resp.body for inspection and testing in varnishtest Needed to test #1123 diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c index 66e1d23..cb58704 100644 --- a/bin/varnishtest/vtc_http.c +++ b/bin/varnishtest/vtc_http.c @@ -196,6 +196,8 @@ cmd_var_resolve(struct http *hp, char *spec) return(hp->chunklen); if (!strcmp(spec, "resp.bodylen")) return(hp->bodylen); + if (!strcmp(spec, "resp.body")) + return(hp->body != NULL ? hp->body : spec); if (!memcmp(spec, "req.http.", 9)) { hh = hp->req; hdr = spec + 9; From tfheen at varnish-cache.org Thu May 24 12:47:42 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:42 +0200 Subject: [3.0] d2e2591 backend cookies Message-ID: commit d2e259199d7f7a1a59f94eac9a283c23bd535fb9 Author: Per Buer Date: Wed Feb 29 16:17:09 2012 +0100 backend cookies diff --git a/doc/sphinx/tutorial/cookies.rst b/doc/sphinx/tutorial/cookies.rst index 0278712..20fd302 100644 --- a/doc/sphinx/tutorial/cookies.rst +++ b/doc/sphinx/tutorial/cookies.rst @@ -13,6 +13,9 @@ This can be overly conservative. A lot of sites use Google Analytics cookie is used by the client side javascript and is therefore of no interest to the server. +Cookies from the client +~~~~~~~~~~~~~~~~~~~~~~~ + For a lot of web application it makes sense to completely disregard the cookies unless you are accessing a special part of the web site. This VCL snippet in vcl_recv will disregard cookies unless you are @@ -63,3 +66,12 @@ cookies named COOKIE1 and COOKIE2 and you can marvel at it:: The example is taken from the Varnish Wiki, where you can find other scary examples of what can be done in VCL. + +Cookies coming from the backend +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +If your backend server sets a cookie using the Set-Cookie header +Varnish will not cache the page. A hit-for-pass object (see +:ref:`tutorial_vcl_fetch_actions`) is created. So, if the backend +server acts silly and sets unwanted cookies just unset the Set-Cookie +header and all should be fine. From tfheen at varnish-cache.org Thu May 24 12:47:43 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:43 +0200 Subject: [3.0] da6775e Fix libedit detection on *BSD OS's Message-ID: commit da6775ef0f4bbc474e2f74e2824743ee91d92f32 Author: Brad Date: Mon Jan 2 14:03:46 2012 -0500 Fix libedit detection on *BSD OS's The following patch allows the autoconf script to detect the presence of libedit when there isn't a pkg-config file present and thus allowing Varnish to detect libedit on OpenBSD/FreeBSD/NetBSD/DragonFly. Fixes: #1003 diff --git a/configure.ac b/configure.ac index 41ddf24..55b2281 100644 --- a/configure.ac +++ b/configure.ac @@ -149,7 +149,14 @@ AC_SUBST(PCRE_LIBS) PKG_CHECK_MODULES([LIBEDIT], [libedit], [AC_DEFINE([HAVE_LIBEDIT], [1], [Define we have libedit])], - [AC_MSG_WARN([libedit not found, disabling libedit support])]) + [AC_CHECK_HEADERS([readline/readline.h]) + AC_CHECK_LIB(edit, el_init, + [ AC_DEFINE([HAVE_LIBEDIT], [1], [Define we have libedit]) + LIBEDIT_CFLAGS="" + LIBEDIT_LIBS="-ledit ${CURSES_LIBS}" + ], + [AC_MSG_WARN([libedit not found, disabling libedit support])], + [${CURSES_LIBS}])]) # Checks for header files. AC_HEADER_STDC From tfheen at varnish-cache.org Thu May 24 12:51:11 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:11 +0200 Subject: [3.0] 09dedf3 Added missing changelog entries from fedora Message-ID: commit 09dedf3c42dd589dc9a0861ce78ef91dee94bb4c Author: Ingvar Hagelund Date: Mon Apr 23 13:13:03 2012 +0200 Added missing changelog entries from fedora diff --git a/redhat/varnish.spec b/redhat/varnish.spec index f25812a..144ace4 100644 --- a/redhat/varnish.spec +++ b/redhat/varnish.spec @@ -241,6 +241,22 @@ fi %postun libs -p /sbin/ldconfig %changelog +* Fri Feb 10 2012 Petr Pisar - 2.1.5-4 +- Rebuild against PCRE 8.30 + +* Sat Jan 14 2012 Fedora Release Engineering - 2.1.5-3 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild + +* Mon Feb 07 2011 Fedora Release Engineering - 2.1.5-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_15_Mass_Rebuild + +* Tue Feb 01 2011 Ingvar Hagelund - 2.1.5-1 +- New upstream release +- New download location +- Moved varnish_reload_vcl to sbin +- Removed patches included upstream +- Use jemalloc as system installed library + * Mon Nov 15 2010 Ingvar Hagelund - 3.0.0-0.svn20101115r5543 - Merged some changes from fedora - Upped general version to 3.0 prerelease in trunk From tfheen at varnish-cache.org Thu May 24 12:47:43 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:43 +0200 Subject: [3.0] b54bfa5 Missing errorchecks incompilation of regsub() Message-ID: commit b54bfa5c2d038cd2ea92a37916821644d56af81b Author: Poul-Henning Kamp Date: Mon Apr 16 07:12:10 2012 +0000 Missing errorchecks incompilation of regsub() Fixes #1125 diff --git a/lib/libvcl/vcc_expr.c b/lib/libvcl/vcc_expr.c index 0c885c0..2ec7dc0 100644 --- a/lib/libvcl/vcc_expr.c +++ b/lib/libvcl/vcc_expr.c @@ -454,6 +454,8 @@ vcc_Eval_Regsub(struct vcc *tl, struct expr **e, const struct symbol *sym) SkipToken(tl, '('); vcc_expr0(tl, &e2, STRING); + if (e2 == NULL) + return; if (e2->fmt != STRING) vcc_expr_tostring(&e2, STRING); @@ -467,6 +469,8 @@ vcc_Eval_Regsub(struct vcc *tl, struct expr **e, const struct symbol *sym) SkipToken(tl, ','); vcc_expr0(tl, &e2, STRING); + if (e2 == NULL) + return; if (e2->fmt != STRING) vcc_expr_tostring(&e2, STRING); *e = vcc_expr_edit(STRING, "\v1, \v2)", *e, e2); From tfheen at varnish-cache.org Thu May 24 12:51:11 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:11 +0200 Subject: [3.0] 87357ee Better fix for #1126 Message-ID: commit 87357eee9c5df596825ee3e0380d2c64b71de142 Author: Poul-Henning Kamp Date: Mon Apr 16 07:22:57 2012 +0000 Better fix for #1126 diff --git a/lib/libvcl/vcc_acl.c b/lib/libvcl/vcc_acl.c index 272f3c6..3e5ac6c 100644 --- a/lib/libvcl/vcc_acl.c +++ b/lib/libvcl/vcc_acl.c @@ -103,7 +103,10 @@ vcc_acl_add_entry(struct vcc *tl, const struct acl_e *ae, int l, if (fam == PF_INET && ae->mask > 32) { VSB_printf(tl->sb, "Too wide mask (%u) for IPv4 address", ae->mask); - vcc_ErrWhere(tl, ae->t_mask); + if (ae->t_mask != NULL) + vcc_ErrWhere(tl, ae->t_mask); + else + vcc_ErrWhere(tl, ae->t_addr); return; } if (fam == PF_INET6 && ae->mask > 128) { @@ -265,10 +268,8 @@ vcc_acl_try_netnotation(struct vcc *tl, struct acl_e *ae) return (0); p += k + 1; } - if (ae->t_mask == NULL) { + if (ae->t_mask == NULL) ae->mask = 8 + 8 * i; - ae->t_mask = ae->t_addr; - } vcc_acl_add_entry(tl, ae, 4, b, AF_INET); return (1); } From tfheen at varnish-cache.org Thu May 24 12:47:44 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:44 +0200 Subject: [3.0] d92617a Removed source installation instructions INSTALL, as requested by rpmlint Message-ID: commit d92617aff2e2ebeb99ebbc052ca27c649720000b Author: Ingvar Hagelund Date: Mon Apr 23 10:52:40 2012 +0200 Removed source installation instructions INSTALL, as requested by rpmlint diff --git a/redhat/varnish.spec b/redhat/varnish.spec index bde3705..484faf9 100644 --- a/redhat/varnish.spec +++ b/redhat/varnish.spec @@ -174,7 +174,7 @@ rm -rf %{buildroot} %{_mandir}/man1/*.1* %{_mandir}/man3/*.3* %{_mandir}/man7/*.7* -%doc INSTALL LICENSE README redhat/README.redhat ChangeLog +%doc LICENSE README redhat/README.redhat ChangeLog %doc examples %dir %{_sysconfdir}/varnish/ %config(noreplace) %{_sysconfdir}/varnish/default.vcl From tfheen at varnish-cache.org Thu May 24 12:51:11 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:11 +0200 Subject: [3.0] 2c7eafa Removed source install instructions from the built package, as requested by rpmlint Message-ID: commit 2c7eafaffda0b71437b0aa01d04708a2c5ff6b55 Author: Ingvar Hagelund Date: Mon Apr 23 10:46:00 2012 +0200 Removed source install instructions from the built package, as requested by rpmlint diff --git a/redhat/varnish.spec b/redhat/varnish.spec index 6f6d71e..3391ed3 100644 --- a/redhat/varnish.spec +++ b/redhat/varnish.spec @@ -174,7 +174,7 @@ rm -rf %{buildroot} %{_mandir}/man1/*.1* %{_mandir}/man3/*.3* %{_mandir}/man7/*.7* -%doc INSTALL LICENSE README redhat/README.redhat ChangeLog +%doc LICENSE README redhat/README.redhat ChangeLog %doc examples %dir %{_sysconfdir}/varnish/ %config(noreplace) %{_sysconfdir}/varnish/default.vcl From tfheen at varnish-cache.org Thu May 24 12:51:11 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:11 +0200 Subject: [3.0] b54bfa5 Missing errorchecks incompilation of regsub() Message-ID: commit b54bfa5c2d038cd2ea92a37916821644d56af81b Author: Poul-Henning Kamp Date: Mon Apr 16 07:12:10 2012 +0000 Missing errorchecks incompilation of regsub() Fixes #1125 diff --git a/lib/libvcl/vcc_expr.c b/lib/libvcl/vcc_expr.c index 0c885c0..2ec7dc0 100644 --- a/lib/libvcl/vcc_expr.c +++ b/lib/libvcl/vcc_expr.c @@ -454,6 +454,8 @@ vcc_Eval_Regsub(struct vcc *tl, struct expr **e, const struct symbol *sym) SkipToken(tl, '('); vcc_expr0(tl, &e2, STRING); + if (e2 == NULL) + return; if (e2->fmt != STRING) vcc_expr_tostring(&e2, STRING); @@ -467,6 +469,8 @@ vcc_Eval_Regsub(struct vcc *tl, struct expr **e, const struct symbol *sym) SkipToken(tl, ','); vcc_expr0(tl, &e2, STRING); + if (e2 == NULL) + return; if (e2->fmt != STRING) vcc_expr_tostring(&e2, STRING); *e = vcc_expr_edit(STRING, "\v1, \v2)", *e, e2); From tfheen at varnish-cache.org Thu May 24 12:47:42 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:42 +0200 Subject: [3.0] e7d1ca8 Use the hash digest as identification instead of the neutered objhead pointer, in order to not have dependency between trouble entry and objhead lifetime. Message-ID: commit e7d1ca8381c7451c10c79ac76d65588f08c011d4 Author: Poul-Henning Kamp Date: Mon Feb 27 12:41:33 2012 +0000 Use the hash digest as identification instead of the neutered objhead pointer, in order to not have dependency between trouble entry and objhead lifetime. Fixes #1091 diff --git a/bin/varnishd/cache_backend.c b/bin/varnishd/cache_backend.c index 7e36bda..c4b9a16 100644 --- a/bin/varnishd/cache_backend.c +++ b/bin/varnishd/cache_backend.c @@ -251,7 +251,6 @@ vbe_Healthy(const struct vdi_simple *vs, const struct sess *sp) unsigned i = 0, retval; unsigned int threshold; struct backend *backend; - uintptr_t target; double now; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); @@ -283,7 +282,6 @@ vbe_Healthy(const struct vdi_simple *vs, const struct sess *sp) return (1); now = sp->t_req; - target = (uintptr_t)(sp->objcore->objhead); old = NULL; retval = 1; @@ -298,7 +296,7 @@ vbe_Healthy(const struct vdi_simple *vs, const struct sess *sp) break; } - if (tr->target == target) { + if (!memcmp(tr->digest, sp->digest, sizeof tr->digest)) { retval = 0; break; } diff --git a/bin/varnishd/cache_backend.h b/bin/varnishd/cache_backend.h index 059b4e7..b16d51e 100644 --- a/bin/varnishd/cache_backend.h +++ b/bin/varnishd/cache_backend.h @@ -97,7 +97,7 @@ struct director { struct trouble { unsigned magic; #define TROUBLE_MAGIC 0x4211ab21 - uintptr_t target; + unsigned char digest[DIGEST_LEN]; double timeout; VTAILQ_ENTRY(trouble) list; }; diff --git a/bin/varnishd/cache_vrt_var.c b/bin/varnishd/cache_vrt_var.c index 2054953..9a2e500 100644 --- a/bin/varnishd/cache_vrt_var.c +++ b/bin/varnishd/cache_vrt_var.c @@ -149,7 +149,7 @@ VRT_l_beresp_saintmode(const struct sess *sp, double a) ALLOC_OBJ(new, TROUBLE_MAGIC); AN(new); - new->target = (uintptr_t)(sp->objcore->objhead); + memcpy(new->digest, sp->digest, sizeof new->digest); new->timeout = sp->t_req + a; /* Insert the new item on the list before the first item with a diff --git a/bin/varnishtest/tests/r01091.vtc b/bin/varnishtest/tests/r01091.vtc new file mode 100644 index 0000000..9234ffc --- /dev/null +++ b/bin/varnishtest/tests/r01091.vtc @@ -0,0 +1,36 @@ +varnishtest "Test fallback director with saint mode" + +server s1 { + rxreq + txresp -hdr "Foo: 1" + accept + rxreq + txresp -hdr "Foo: 1" +} -start + +server s2 { + rxreq + txresp -hdr "Foo: 2" -bodylen 1 +} -start + +varnish v1 -vcl+backend { + director f1 fallback { + { .backend = s1; } + { .backend = s2; } + } + sub vcl_recv { + set req.backend = f1; + } + sub vcl_fetch { + if(req.restarts < 1) { + set beresp.saintmode = 1h; + return(restart); + } + } +} -start + +client c1 { + txreq + rxresp + expect resp.http.foo == "2" +} -run From tfheen at varnish-cache.org Thu May 24 12:51:12 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:12 +0200 Subject: [3.0] d6bc813 Fix ttl when backend fetches are salvaged into transient storage. Message-ID: commit d6bc813c8e08d7aaa20e27d52cf330d0548c7e9b Author: Poul-Henning Kamp Date: Mon May 21 07:23:27 2012 +0000 Fix ttl when backend fetches are salvaged into transient storage. Submitted by: Martin Fixes #1140 diff --git a/bin/varnishd/cache_center.c b/bin/varnishd/cache_center.c index bf08fb0..23183ed 100644 --- a/bin/varnishd/cache_center.c +++ b/bin/varnishd/cache_center.c @@ -788,12 +788,12 @@ cnt_fetchbody(struct sess *sp) * Try to salvage the transaction by allocating a * shortlived object on Transient storage. */ - sp->obj = STV_NewObject(sp, TRANSIENT_STORAGE, l, - &sp->wrk->exp, nhttp); if (sp->wrk->exp.ttl > params->shortlived) sp->wrk->exp.ttl = params->shortlived; sp->wrk->exp.grace = 0.0; sp->wrk->exp.keep = 0.0; + sp->obj = STV_NewObject(sp, TRANSIENT_STORAGE, l, + &sp->wrk->exp, nhttp); } if (sp->obj == NULL) { sp->err_code = 503; From tfheen at varnish-cache.org Thu May 24 12:51:09 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:09 +0200 Subject: [3.0] 1b93331 remove the experimental flag from http_range_support Message-ID: commit 1b933317b9b9f6a777f9a45908deb37e28470b38 Author: Per Buer Date: Thu Jan 19 10:54:34 2012 +0100 remove the experimental flag from http_range_support diff --git a/bin/varnishd/mgt_param.c b/bin/varnishd/mgt_param.c index 76d9fe2..16bbb7d 100644 --- a/bin/varnishd/mgt_param.c +++ b/bin/varnishd/mgt_param.c @@ -870,7 +870,7 @@ static const struct parspec input_parspec[] = { "10", "objects" }, { "http_range_support", tweak_bool, &master.http_range_support, 0, 0, "Enable support for HTTP Range headers.\n", - EXPERIMENTAL, + 0, "on", "bool" }, { "http_gzip_support", tweak_bool, &master.http_gzip_support, 0, 0, "Enable gzip support. When enabled Varnish will compress " From tfheen at varnish-cache.org Thu May 24 12:51:11 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:11 +0200 Subject: [3.0] e43966d escape \0 Message-ID: commit e43966d7c8516b6d5b49d4084cc38b4fbcdc56a0 Author: Per Buer Date: Wed Apr 4 10:17:01 2012 +0200 escape \0 diff --git a/doc/sphinx/reference/vcl.rst b/doc/sphinx/reference/vcl.rst index 01d783f..212cd2b 100644 --- a/doc/sphinx/reference/vcl.rst +++ b/doc/sphinx/reference/vcl.rst @@ -420,7 +420,7 @@ hash_data(str) regsub(str, regex, sub) Returns a copy of str with the first occurrence of the regular - expression regex replaced with sub. Within sub, \0 (which can + expression regex replaced with sub. Within sub, \\0 (which can also be spelled &) is replaced with the entire matched string, and \n is replaced with the contents of subgroup n in the matched string. From tfheen at varnish-cache.org Thu May 24 12:51:11 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:11 +0200 Subject: [3.0] 444e642 Add an explicit macro_undef() function so we don't pass a NULL argument to a printflike function. Message-ID: commit 444e642f78ddc3bccea79d7c7707c6f0517bdb69 Author: Poul-Henning Kamp Date: Mon Apr 23 11:35:56 2012 +0000 Add an explicit macro_undef() function so we don't pass a NULL argument to a printflike function. diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c index 53cbdcd..72caa2a 100644 --- a/bin/varnishtest/vtc.c +++ b/bin/varnishtest/vtc.c @@ -90,6 +90,8 @@ macro_def(struct vtclog *vl, const char *instance, const char *name, struct macro *m; va_list ap; + AN(fmt); + if (instance != NULL) { bprintf(buf1, "%s_%s", instance, name); name = buf1; @@ -99,23 +101,40 @@ macro_def(struct vtclog *vl, const char *instance, const char *name, VTAILQ_FOREACH(m, ¯o_list, list) if (!strcmp(name, m->name)) break; - if (m == NULL && fmt != NULL) { + if (m == NULL) { m = calloc(sizeof *m, 1); AN(m); REPLACE(m->name, name); VTAILQ_INSERT_TAIL(¯o_list, m, list); } - if (fmt != NULL) { - AN(m); - va_start(ap, fmt); - free(m->val); - m->val = NULL; - vbprintf(buf2, fmt, ap); - va_end(ap); - m->val = strdup(buf2); - AN(m->val); - vtc_log(vl, 4, "macro def %s=%s", name, m->val); - } else if (m != NULL) { + AN(m); + va_start(ap, fmt); + free(m->val); + m->val = NULL; + vbprintf(buf2, fmt, ap); + va_end(ap); + m->val = strdup(buf2); + AN(m->val); + vtc_log(vl, 4, "macro def %s=%s", name, m->val); + AZ(pthread_mutex_unlock(¯o_mtx)); +} + +void +macro_undef(struct vtclog *vl, const char *instance, const char *name) +{ + char buf1[256]; + struct macro *m; + + if (instance != NULL) { + bprintf(buf1, "%s_%s", instance, name); + name = buf1; + } + + AZ(pthread_mutex_lock(¯o_mtx)); + VTAILQ_FOREACH(m, ¯o_list, list) + if (!strcmp(name, m->name)) + break; + if (m != NULL) { vtc_log(vl, 4, "macro undef %s", name); VTAILQ_REMOVE(¯o_list, m, list); free(m->name); diff --git a/bin/varnishtest/vtc.h b/bin/varnishtest/vtc.h index 16861d3..2ee284f 100644 --- a/bin/varnishtest/vtc.h +++ b/bin/varnishtest/vtc.h @@ -80,6 +80,7 @@ void vtc_hexdump(struct vtclog *vl, int lvl, const char *pfx, int exec_file(const char *fn, const char *script, const char *tmpdir, char *logbuf, unsigned loglen); +void macro_undef(struct vtclog *vl, const char *instance, const char *name); void macro_def(struct vtclog *vl, const char *instance, const char *name, const char *fmt, ...); struct vsb *macro_expand(struct vtclog *vl, const char *text); diff --git a/bin/varnishtest/vtc_server.c b/bin/varnishtest/vtc_server.c index d1787b1..04a1bed 100644 --- a/bin/varnishtest/vtc_server.c +++ b/bin/varnishtest/vtc_server.c @@ -147,9 +147,9 @@ server_delete(struct server *s) { CHECK_OBJ_NOTNULL(s, SERVER_MAGIC); - macro_def(s->vl, s->name, "addr", NULL); - macro_def(s->vl, s->name, "port", NULL); - macro_def(s->vl, s->name, "sock", NULL); + macro_undef(s->vl, s->name, "addr"); + macro_undef(s->vl, s->name, "port"); + macro_undef(s->vl, s->name, "sock"); vtc_logclose(s->vl); free(s->name); /* XXX: MEMLEAK (?) (VSS ??) */ diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c index 1b3b445..e97fab2 100644 --- a/bin/varnishtest/vtc_varnish.c +++ b/bin/varnishtest/vtc_varnish.c @@ -527,9 +527,9 @@ varnish_stop(struct varnish *v) varnish_launch(v); if (vtc_error) return; - macro_def(v->vl, v->name, "addr", NULL); - macro_def(v->vl, v->name, "port", NULL); - macro_def(v->vl, v->name, "sock", NULL); + macro_undef(v->vl, v->name, "addr"); + macro_undef(v->vl, v->name, "port"); + macro_undef(v->vl, v->name, "sock"); vtc_log(v->vl, 2, "Stop"); (void)varnish_ask_cli(v, "stop", NULL); while (1) { From tfheen at varnish-cache.org Thu May 24 12:47:44 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:44 +0200 Subject: [3.0] dd0d586 Clean up docs about esi:remove and +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +The and constructs can be used to present +appropriate content whether or not ESI is available, for example you can +include content when ESI is available or link to it when it is not. +ESI processors will remove the start ("") when +the page is processed, while still processing the contents. If the page +is not processed, it will remain, becoming an HTML/XML comment tag. +ESI processors will remove tags and all content contained +in them, allowing you to only render the content when the page is not +being ESI-processed. +For example:: - - www.example.com + The license - -Example: -~~~~~~~~~~~~~~~~~~~~~~~~ - - -This is a special construct to allow HTML marked up with ESI to render -without processing. ESI Processors will remove the start ("") when the page is processed, while still processing the -contents. If the page is not processed, it will remain, becoming an -HTML/XML comment tag. For example:: - - -This assures that the ESI markup will not interfere with the rendering -of the final HTML if not processed. - - +

The full text of the license:

+ + --> From tfheen at varnish-cache.org Thu May 24 12:47:45 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:45 +0200 Subject: [3.0] 8015b1a Duration needs a unit Message-ID: commit 8015b1ab869a60cb220b5d20ef7b6d183cea64ab Author: Andreas Plesner Jacobsen Date: Thu May 24 14:17:52 2012 +0200 Duration needs a unit diff --git a/doc/sphinx/reference/vmod_std.rst b/doc/sphinx/reference/vmod_std.rst index a1ece16..984331e 100644 --- a/doc/sphinx/reference/vmod_std.rst +++ b/doc/sphinx/reference/vmod_std.rst @@ -124,7 +124,7 @@ Description the usual s (seconds), m (minutes), h (hours), d (days) and w (weeks) units. If *s* fails to parse, *fallback* will be used. Example - set beresp.ttl = std.duration("1w", 3600); + set beresp.ttl = std.duration("1w", 3600s); integer -------- From tfheen at varnish-cache.org Thu May 24 12:51:10 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:10 +0200 Subject: [3.0] cfdf155 typos, change example3 to allow for easier purging Message-ID: commit cfdf15518595603a49bf4bf4c550cbcf1b9fe07c Author: Lasse Karstensen Date: Thu Mar 8 14:26:27 2012 +0100 typos, change example3 to allow for easier purging diff --git a/doc/sphinx/tutorial/devicedetection.rst b/doc/sphinx/tutorial/devicedetection.rst index a083e6e..abf729e 100644 --- a/doc/sphinx/tutorial/devicedetection.rst +++ b/doc/sphinx/tutorial/devicedetection.rst @@ -27,8 +27,10 @@ Setting this header can be as simple as:: } } -There are different commercial and free offerings in doing grouping and identifiying clients -in further detail than this. +There are different commercial and free offerings in doing grouping and +identifiying clients in further detail than this. For a basic and community +based regular expression set, see +https://github.com/varnish/varnish-devicedetect/ . Serve the different content on the same URL @@ -45,14 +47,14 @@ Varnish' internal handling of this kicks in. 4. Modify output sent to the client so any caches outside our control don't serve the wrong content. -All this while still making sure that we only get 1 cache object per URL per +All this while still making sure that we only get 1 cached object per URL per device class. Example 1: Send HTTP header to backend '''''''''''''''''''''''''''''''''''''' -The basic case is that Varnish add the X-UA-Device HTTP header on the backend +The basic case is that Varnish adds the X-UA-Device HTTP header on the backend requests, and the backend mentions in the response Vary header that the content is dependant on this header. @@ -64,17 +66,7 @@ VCL:: sub vcl_recv { # call some detection engine that set req.http.X-UA-Device } - - sub append_ua_device { - if (req.http.X-UA-Device) { - set bereq.http.X-UA-Device = req.http.X-UA-Device; } - } - - # This must be done in vcl_miss and vcl_pass, before any backend request is - # actually sent. vcl_fetch runs after the request to the backend has - # completed. - sub vcl_miss { call append_ua_device; } - sub vcl_pass { call append_ua_device; } + # req.http.X-UA-Device is copied by Varnish into bereq.http.X-UA-Device # so, this is a bit conterintuitive. The backend creates content based on # the normalized User-Agent, but we use Vary on X-UA-Device so Varnish will @@ -170,7 +162,9 @@ VCL:: sub vcl_recv { # call some detection engine that set req.http.X-UA-Device + } + sub append_ua { if ((req.http.X-UA-Device) && (req.request == "GET")) { # if there are existing GET arguments; if (req.url ~ "\?") { @@ -183,6 +177,10 @@ VCL:: } } + # do this after vcl_hash, so all Vary-ants can be purged in one go. (avoid ban()ing) + sub vcl_miss { call append_ua; } + sub vcl_pass { call append_ua; } + # Handle redirects, otherwise standard Vary handling code from previous # examples. sub vcl_fetch { From tfheen at varnish-cache.org Thu May 24 12:51:11 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:11 +0200 Subject: [3.0] c9366e5 :: need to be on a separate line in RST. Message-ID: commit c9366e5f2eaba0f27701a5bbe55862b6202e1cef Author: Per Buer Date: Mon Apr 16 13:37:47 2012 +0200 :: need to be on a separate line in RST. diff --git a/doc/sphinx/reference/vcl.rst b/doc/sphinx/reference/vcl.rst index ff92c56..01d783f 100644 --- a/doc/sphinx/reference/vcl.rst +++ b/doc/sphinx/reference/vcl.rst @@ -96,14 +96,16 @@ file as a quoted string. Backend declarations -------------------- -A backend declaration creates and initializes a named backend object:: +A backend declaration creates and initializes a named backend object: +:: backend www { .host = "www.example.com"; .port = "http"; } -The backend object can later be used to select a backend at request time:: +The backend object can later be used to select a backend at request time: +:: if (req.http.host ~ "(?i)^(www.)?example.com$") { set req.backend = www; @@ -118,7 +120,8 @@ backend connection, .first_byte_timeout for the time to wait for the first byte from the backend and .between_bytes_timeout for time to wait between each received byte. -These can be set in the declaration like this:: +These can be set in the declaration like this: +:: backend www { .host = "www.example.com"; @@ -145,7 +148,8 @@ be used. There are several types of directors. The different director types use different algorithms to choose which backend to use. -Configuring a director may look like this:: +Configuring a director may look like this: +:: director b2 random { .retries = 5; @@ -226,7 +230,8 @@ The DNS director ~~~~~~~~~~~~~~~~ The DNS director can use backends in two different ways. Either like the -random or round-robin director or using .list:: +random or round-robin director or using .list: +:: director directorname dns { .list = { @@ -266,7 +271,8 @@ considers them in the order in which they are listed in its definition. The fallback director does not take any options. -An example of a fallback director:: +An example of a fallback director: +:: director b3 fallback { { .backend = www1; } @@ -312,7 +318,8 @@ Probes take the following parameters: Default is 2 seconds. A backend with a probe can be defined like this, together with the -backend or director:: +backend or director: +:: backend www { .host = "www.example.com"; @@ -326,7 +333,8 @@ backend or director:: } } -Or it can be defined separately and then referenced:: +Or it can be defined separately and then referenced: +:: probe healthcheck { .url = "/status.cgi"; @@ -347,7 +355,8 @@ Or it can be defined separately and then referenced:: If you have many backends this can simplify the config a lot. -It is also possible to specify the raw HTTP request:: +It is also possible to specify the raw HTTP request: +:: probe rawprobe { # NB: \r\n automatically inserted after each string! @@ -361,7 +370,8 @@ ACLs ---- An ACL declaration creates and initializes a named access control list -which can later be used to match client addresses:: +which can later be used to match client addresses: +:: acl local { "localhost"; // myself @@ -375,7 +385,8 @@ if it is preceded by a negation mark, it will reject any address it is compared to, which may not be what you intended. If the entry is enclosed in parentheses, however, it will simply be ignored. -To match an IP address against an ACL, simply use the match operator:: +To match an IP address against an ACL, simply use the match operator: +:: if (client.ip ~ local) { return (pipe); @@ -390,7 +401,8 @@ PCRE(3) man page. To send flags to the PCRE engine, such as to turn on *case insensitivity* add the flag within parens following a question mark, -like this:: +like this: +:: if (req.http.host ~ "(?i)example.com$") { ... @@ -424,7 +436,8 @@ ban_url(regex) Subroutines ~~~~~~~~~~~ -A subroutine is used to group code for legibility or reusability:: +A subroutine is used to group code for legibility or reusability: +:: sub pipe_if_local { if (client.ip ~ local) { @@ -640,7 +653,8 @@ appear in the source. The default versions distributed with Varnish will be implicitly concatenated as a last resort at the end. -Example:: +Example: +:: # in file "main.vcl" include "backends.vcl"; @@ -887,7 +901,8 @@ resp.response resp.http.header The corresponding HTTP header. -Values may be assigned to variables using the set keyword:: +Values may be assigned to variables using the set keyword: +:: sub vcl_recv { # Normalize the Host: header @@ -896,7 +911,8 @@ Values may be assigned to variables using the set keyword:: } } -HTTP headers can be removed entirely using the remove keyword:: +HTTP headers can be removed entirely using the remove keyword: +:: sub vcl_fetch { # Don't cache cookies @@ -913,7 +929,8 @@ fresh object is being generated by the backend. The following vcl code will make Varnish serve expired objects. All object will be kept up to two minutes past their expiration time or a -fresh object is generated.:: +fresh object is generated. +:: sub vcl_recv { set req.grace = 2m; @@ -938,7 +955,8 @@ EXAMPLES The following code is the equivalent of the default configuration with the backend address set to "backend.example.com" and no backend port -specified:: +specified: +:: backend default { .host = "backend.example.com"; @@ -950,7 +968,8 @@ specified:: The following example shows how to support multiple sites running on separate backends in the same Varnish instance, by selecting backends -based on the request URL:: +based on the request URL: +:: backend www { .host = "www.example.com"; @@ -976,7 +995,8 @@ based on the request URL:: The following snippet demonstrates how to force a minimum TTL for all documents. Note that this is not the same as setting the default_ttl run-time parameter, as that only affects document for -which the backend did not specify a TTL:: +which the backend did not specify a TTL: +:: import std; # needed for std.log @@ -988,7 +1008,8 @@ which the backend did not specify a TTL:: } The following snippet demonstrates how to force Varnish to cache -documents even when cookies are present:: +documents even when cookies are present: +:: sub vcl_recv { if (req.request == "GET" && req.http.cookie) { @@ -1003,7 +1024,8 @@ documents even when cookies are present:: } The following code implements the HTTP PURGE method as used by Squid -for object invalidation:: +for object invalidation: +:: acl purge { "localhost"; From tfheen at varnish-cache.org Thu May 24 12:47:45 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:45 +0200 Subject: [3.0] 79db58a Use admin health to control test-state Message-ID: commit 79db58ace109a60f5bc878ff99920fdef5c952fe Author: Poul-Henning Kamp Date: Thu May 10 09:09:49 2012 +0000 Use admin health to control test-state diff --git a/bin/varnishtest/tests/r00306.vtc b/bin/varnishtest/tests/r00306.vtc index ebc1774..079e994 100644 --- a/bin/varnishtest/tests/r00306.vtc +++ b/bin/varnishtest/tests/r00306.vtc @@ -23,10 +23,6 @@ varnish v1 -vcl { } backend s2 { .host = "${s2_addr}"; .port = "${s2_port}"; - .probe = { - .url = "/"; - .initial = 0; - } } director foo random { { .backend = s2; .weight = 1; } @@ -38,6 +34,9 @@ varnish v1 -vcl { } } -start +varnish v1 -cliok "backend.set_health s2 sick" +varnish v1 -cliok "backend.list" + client c1 { timeout 10 From tfheen at varnish-cache.org Thu May 24 12:47:44 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:44 +0200 Subject: [3.0] 2c7eafa Removed source install instructions from the built package, as requested by rpmlint Message-ID: commit 2c7eafaffda0b71437b0aa01d04708a2c5ff6b55 Author: Ingvar Hagelund Date: Mon Apr 23 10:46:00 2012 +0200 Removed source install instructions from the built package, as requested by rpmlint diff --git a/redhat/varnish.spec b/redhat/varnish.spec index 6f6d71e..3391ed3 100644 --- a/redhat/varnish.spec +++ b/redhat/varnish.spec @@ -174,7 +174,7 @@ rm -rf %{buildroot} %{_mandir}/man1/*.1* %{_mandir}/man3/*.3* %{_mandir}/man7/*.7* -%doc INSTALL LICENSE README redhat/README.redhat ChangeLog +%doc LICENSE README redhat/README.redhat ChangeLog %doc examples %dir %{_sysconfdir}/varnish/ %config(noreplace) %{_sysconfdir}/varnish/default.vcl From tfheen at varnish-cache.org Thu May 24 12:47:43 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:43 +0200 Subject: [3.0] 2a5f37f Add section on device detection Message-ID: commit 2a5f37f415b4fdfc4103cb53c3b2c0c95818586f Author: Lasse Karstensen Date: Wed Mar 7 14:35:41 2012 +0100 Add section on device detection diff --git a/doc/sphinx/tutorial/devicedetection.rst b/doc/sphinx/tutorial/devicedetection.rst new file mode 100644 index 0000000..a083e6e --- /dev/null +++ b/doc/sphinx/tutorial/devicedetection.rst @@ -0,0 +1,260 @@ +.. _tutorial-devicedetect: + +Device detection +~~~~~~~~~~~~~~~~ + +Device detection is figuring out what kind of content to serve to a +client based on the User-Agent string supplied in a request. + +Use cases for this are for example to send size reduced files to mobile +clients with small screens and on high latency networks, or to +provide a streaming video codec that the client understands. + +There are a couple of strategies on what to do with such clients: +1) Redirect them to another URL. +2) Use a different backend for the special clients. +3) Change the backend requests so the usual backend sends tailored content. + +To make the examples easier to understand, it is assumed in this text +that all the req.http.X-UA-Device header is present and unique per client class +that content is to be served to. + +Setting this header can be as simple as:: + + sub vcl_recv {? + if (req.http.User-Agent ~ "(?i)iphone"?{ + set req.http.X-UA-Device = "mobile-iphone"; + } + } + +There are different commercial and free offerings in doing grouping and identifiying clients +in further detail than this. + + +Serve the different content on the same URL +------------------------------------------- + +The tricks involved are: +1. Detect the client (pretty simple, just include devicedetect.vcl and call +it) +2. Figure out how to signal the backend what client class this is. This +includes for example setting a header, changing a header or even changing the +backend request URL. +3. Modify any response from the backend to add missing Vary headers, so +Varnish' internal handling of this kicks in. +4. Modify output sent to the client so any caches outside our control don't +serve the wrong content. + +All this while still making sure that we only get 1 cache object per URL per +device class. + + +Example 1: Send HTTP header to backend +'''''''''''''''''''''''''''''''''''''' + +The basic case is that Varnish add the X-UA-Device HTTP header on the backend +requests, and the backend mentions in the response Vary header that the content +is dependant on this header. + +Everything works out of the box from Varnish' perspective. + +.. 071-example1-start +VCL:: + + sub vcl_recv { + # call some detection engine that set req.http.X-UA-Device + } + + sub append_ua_device { + if (req.http.X-UA-Device) { + set bereq.http.X-UA-Device = req.http.X-UA-Device; } + } + + # This must be done in vcl_miss and vcl_pass, before any backend request is + # actually sent. vcl_fetch runs after the request to the backend has + # completed. + sub vcl_miss { call append_ua_device; } + sub vcl_pass { call append_ua_device; } + + # so, this is a bit conterintuitive. The backend creates content based on + # the normalized User-Agent, but we use Vary on X-UA-Device so Varnish will + # use the same cached object for all U-As that map to the same X-UA-Device. + # + # If the backend does not mention in Vary that it has crafted special + # content based on the User-Agent (==X-UA-Device), add it. + # If your backend does set Vary: User-Agent, you may have to remove that here. + sub vcl_fetch { + if (req.http.X-UA-Device) { + if (!beresp.http.Vary) { # no Vary at all + set beresp.http.Vary = "X-UA-Device"; + } elseif (beresp.http.Vary !~ "X-UA-Device") { # add to existing Vary + set beresp.http.Vary = beresp.http.Vary + ", X-UA-Device"; + } + } + # comment this out if you don't want the client to know your + # classification + set beresp.http.X-UA-Device = req.http.X-UA-Device; + } + + # to keep any caches in the wild from serving wrong content to client #2 + # behind them, we need to transform the Vary on the way out. + sub vcl_deliver { + if ((req.http.X-UA-Device) && (resp.http.Vary)) { + set resp.http.Vary = regsub(resp.http.Vary, "X-UA-Device", "User-Agent"); + } + } +.. 071-example1-end + +Example 2: Normalize the User-Agent string +'''''''''''''''''''''''''''''''''''''''''' + +Another way of signaling the device type is to override or normalize the +User-Agent header sent to the backend. + +For example + + User-Agent: Mozilla/5.0 (Linux; U; Android 2.2; nb-no; HTC Desire Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 + +becomes: + + User-Agent: mobile-android + +when seen by the backend. + +This works if you don't need the original header for anything on the backend. +A possible use for this is for CGI scripts where only a small set of predefined +headers are (by default) available for the script. + +.. 072-example2-start +VCL:: + + sub vcl_recv { + # call some detection engine that set req.http.X-UA-Device + } + + # override the header before it is sent to the backend + sub vcl_miss { if (req.http.X-UA-Device) { set bereq.http.User-Agent = req.http.X-UA-Device; } } + sub vcl_pass { if (req.http.X-UA-Device) { set bereq.http.User-Agent = req.http.X-UA-Device; } } + + # standard Vary handling code from previous examples. + sub vcl_fetch { + if (req.http.X-UA-Device) { + if (!beresp.http.Vary) { # no Vary at all + set beresp.http.Vary = "X-UA-Device"; + } elseif (beresp.http.Vary !~ "X-UA-Device") { # add to existing Vary + set beresp.http.Vary = beresp.http.Vary + ", X-UA-Device"; + } + } + set beresp.http.X-UA-Device = req.http.X-UA-Device; + } + sub vcl_deliver { + if ((req.http.X-UA-Device) && (resp.http.Vary)) { + set resp.http.Vary = regsub(resp.http.Vary, "X-UA-Device", "User-Agent"); + } + } + +.. 072-example2-end + +Example 3: Add the device class as a GET query parameter +'''''''''''''''''''''''''''''''''''''''''''''''''''''''' + +If everything else fails, you can add the device type as a GET argument. + + http://example.com/article/1234.html --> http://example.com/article/1234.html?devicetype=mobile-iphone + +The client itself does not see this classification, only the backend request +is changed. + +.. 073-example3-start +VCL:: + + sub vcl_recv { + # call some detection engine that set req.http.X-UA-Device + + if ((req.http.X-UA-Device) && (req.request == "GET")) { + # if there are existing GET arguments; + if (req.url ~ "\?") { + set req.http.X-get-devicetype = "&devicetype=" + req.http.X-UA-Device; + } else { + set req.http.X-get-devicetype = "?devicetype=" + req.http.X-UA-Device; + } + set req.url = req.url + req.http.X-get-devicetype; + unset req.http.X-get-devicetype; + } + } + + # Handle redirects, otherwise standard Vary handling code from previous + # examples. + sub vcl_fetch { + if (req.http.X-UA-Device) { + if (!beresp.http.Vary) { # no Vary at all + set beresp.http.Vary = "X-UA-Device"; + } elseif (beresp.http.Vary !~ "X-UA-Device") { # add to existing Vary + set beresp.http.Vary = beresp.http.Vary + ", X-UA-Device"; + } + + # if the backend returns a redirect (think missing trailing slash), + # we will potentially show the extra address to the client. we + # don't want that. if the backend reorders the get parameters, you + # may need to be smarter here. (? and & ordering) + + if (beresp.status == 301 || beresp.status == 302 || beresp.status == 303) { + set beresp.http.location = regsub(beresp.http.location, "[?&]devicetype=.*$", ""); + } + } + set beresp.http.X-UA-Device = req.http.X-UA-Device; + } + sub vcl_deliver { + if ((req.http.X-UA-Device) && (resp.http.Vary)) { + set resp.http.Vary = regsub(resp.http.Vary, "X-UA-Device", "User-Agent"); + } + } + +.. 073-example3-end + +Different backend for mobile clients +------------------------------------ + +If you have a different backend that serves pages for mobile clients, or any +special needs in VCL, you can use the X-UA-Device header like this:: + + backend mobile { + .host = "10.0.0.1"; + .port = "80"; + } + + sub vcl_recv { + # call some detection engine + + if (req.http.X-UA-Device ~ "^mobile" || req.http.X-UA-device ~ "^tablet") { + set req.backend = mobile; + } + } + +Redirecting mobile clients +-------------------------- + +If you want to redirect mobile clients you can use the following snippet. + +.. 065-redir-mobile-start +VCL:: + + sub vcl_recv { + # call some detection engine + + if (req.http.X-UA-Device ~ "^mobile" || req.http.X-UA-device ~ "^tablet") { + error 750 "Moved Temporarily"; + } + } + + sub vcl_error { + if (obj.status == 750) { + set obj.http.Location = "http://m.example.com" + req.url; + set obj.status = 302; + return(deliver); + } + } + +.. 065-redir-mobile-end + + diff --git a/doc/sphinx/tutorial/index.rst b/doc/sphinx/tutorial/index.rst index 6769ec4..d41bfbb 100644 --- a/doc/sphinx/tutorial/index.rst +++ b/doc/sphinx/tutorial/index.rst @@ -30,6 +30,7 @@ separate topic. Good luck. esi virtualised websockets + devicedetection advanced_backend_servers handling_misbehaving_servers advanced_topics From tfheen at varnish-cache.org Thu May 24 12:51:11 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:11 +0200 Subject: [3.0] 2c4317d Stopped using macros for make and install, according to Fedora's packaging guidelines Message-ID: commit 2c4317d1338a9c451ea2de542f7894c5bb3e79e6 Author: Ingvar Hagelund Date: Mon Apr 23 10:50:41 2012 +0200 Stopped using macros for make and install, according to Fedora's packaging guidelines diff --git a/redhat/varnish.spec b/redhat/varnish.spec index 3391ed3..bde3705 100644 --- a/redhat/varnish.spec +++ b/redhat/varnish.spec @@ -153,13 +153,13 @@ find %{buildroot}/%{_libdir}/ -name '*.la' -exec rm -f {} ';' mkdir -p %{buildroot}/var/lib/varnish mkdir -p %{buildroot}/var/log/varnish mkdir -p %{buildroot}/var/run/varnish -%{__install} -D -m 0644 redhat/default.vcl %{buildroot}%{_sysconfdir}/varnish/default.vcl -%{__install} -D -m 0644 redhat/varnish.sysconfig %{buildroot}%{_sysconfdir}/sysconfig/varnish -%{__install} -D -m 0644 redhat/varnish.logrotate %{buildroot}%{_sysconfdir}/logrotate.d/varnish -%{__install} -D -m 0755 redhat/varnish.initrc %{buildroot}%{_initrddir}/varnish -%{__install} -D -m 0755 redhat/varnishlog.initrc %{buildroot}%{_initrddir}/varnishlog -%{__install} -D -m 0755 redhat/varnishncsa.initrc %{buildroot}%{_initrddir}/varnishncsa -%{__install} -D -m 0755 redhat/varnish_reload_vcl %{buildroot}%{_bindir}/varnish_reload_vcl +install -D -m 0644 redhat/default.vcl %{buildroot}%{_sysconfdir}/varnish/default.vcl +install -D -m 0644 redhat/varnish.sysconfig %{buildroot}%{_sysconfdir}/sysconfig/varnish +install -D -m 0644 redhat/varnish.logrotate %{buildroot}%{_sysconfdir}/logrotate.d/varnish +install -D -m 0755 redhat/varnish.initrc %{buildroot}%{_initrddir}/varnish +install -D -m 0755 redhat/varnishlog.initrc %{buildroot}%{_initrddir}/varnishlog +install -D -m 0755 redhat/varnishncsa.initrc %{buildroot}%{_initrddir}/varnishncsa +install -D -m 0755 redhat/varnish_reload_vcl %{buildroot}%{_bindir}/varnish_reload_vcl %clean rm -rf %{buildroot} @@ -174,7 +174,7 @@ rm -rf %{buildroot} %{_mandir}/man1/*.1* %{_mandir}/man3/*.3* %{_mandir}/man7/*.7* -%doc LICENSE README redhat/README.redhat ChangeLog +%doc INSTALL LICENSE README redhat/README.redhat ChangeLog %doc examples %dir %{_sysconfdir}/varnish/ %config(noreplace) %{_sysconfdir}/varnish/default.vcl From tfheen at varnish-cache.org Thu May 24 12:47:43 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:47:43 +0200 Subject: [3.0] 8a47021 Correct function name Message-ID: commit 8a47021105c231dd6d37ce643da2bd5feef6c816 Author: Andreas Plesner Jacobsen Date: Mon Mar 12 12:23:47 2012 +0100 Correct function name diff --git a/doc/sphinx/reference/vmod_std.rst b/doc/sphinx/reference/vmod_std.rst index 9c28a3c..a1ece16 100644 --- a/doc/sphinx/reference/vmod_std.rst +++ b/doc/sphinx/reference/vmod_std.rst @@ -50,7 +50,7 @@ Description Example set beresp.http.x-nice = std.tolower("VerY"); -set_up_tos +set_ip_tos ---------- Prototype set_ip_tos(INT i) From tfheen at varnish-cache.org Thu May 24 12:51:12 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Thu, 24 May 2012 14:51:12 +0200 Subject: [3.0] 68acd5b Add code coverage of the RST dumping code Message-ID: commit 68acd5b94fd130cae510dafb1726a7cc60a861b0 Author: Poul-Henning Kamp Date: Wed May 2 08:47:15 2012 +0000 Add code coverage of the RST dumping code diff --git a/bin/varnishtest/tests/a00009.vtc b/bin/varnishtest/tests/a00009.vtc index 4d35f85..f89231f 100644 --- a/bin/varnishtest/tests/a00009.vtc +++ b/bin/varnishtest/tests/a00009.vtc @@ -1,3 +1,4 @@ -varnishtest "See that the VCL compiler works" +varnishtest "Code coverage of VCL compiler and RSTdump" shell "cd ${topbuild}/bin/varnishd && ./varnishd -b 127.0.0.1:80 -C -n ${tmpdir} > /dev/null 2>&1" +shell "cd ${topbuild}/bin/varnishd && ./varnishd -x dumprst > /dev/null 2>&1" From phk at varnish-cache.org Tue May 29 07:03:02 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Tue, 29 May 2012 09:03:02 +0200 Subject: [master] cf811a3 Give struct req a back pointer to struct sess Message-ID: commit cf811a3e0461e4c0112ad9906a12004bfb28b88b Author: Poul-Henning Kamp Date: Tue May 29 06:38:37 2012 +0000 Give struct req a back pointer to struct sess diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index ee17d31..93e05e7 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -561,6 +561,8 @@ struct req { uint8_t hash_ignore_busy; uint8_t hash_always_miss; + struct sess *sp; + /* The busy objhead we sleep on */ struct objhead *hash_objhead; struct busyobj *busyobj; diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index ba52ad3..3a85baf 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -291,6 +291,7 @@ void SES_GetReq(struct sess *sp) { struct sesspool *pp; + struct req *req; uint16_t nhttp; unsigned sz, hl; char *p, *e; @@ -301,42 +302,44 @@ SES_GetReq(struct sess *sp) AN(pp->pool); AZ(sp->req); - sp->req = MPL_Get(pp->mpl_req, &sz); - AN(sp->req); - sp->req->magic = REQ_MAGIC; - - e = (char*)sp->req + sz; - p = (char*)(sp->req + 1); + req = MPL_Get(pp->mpl_req, &sz); + AN(req); + req->magic = REQ_MAGIC; + sp->req = req; + req->sp = sp; + + e = (char*)req + sz; + p = (char*)(req + 1); p = (void*)PRNDUP(p); assert(p < e); nhttp = (uint16_t)cache_param->http_max_hdr; hl = HTTP_estimate(nhttp); - sp->req->http = HTTP_create(p, nhttp); + req->http = HTTP_create(p, nhttp); p += hl; p = (void*)PRNDUP(p); assert(p < e); - sp->req->http0 = HTTP_create(p, nhttp); + req->http0 = HTTP_create(p, nhttp); p += hl; p = (void*)PRNDUP(p); assert(p < e); - sp->req->resp = HTTP_create(p, nhttp); + req->resp = HTTP_create(p, nhttp); p += hl; p = (void*)PRNDUP(p); assert(p < e); sz = cache_param->workspace_thread; - VSL_Setup(sp->req->vsl, p, sz); - sp->req->vsl->wid = sp->vsl_id; + VSL_Setup(req->vsl, p, sz); + req->vsl->wid = sp->vsl_id; p += sz; p = (void*)PRNDUP(p); assert(p < e); - WS_Init(sp->req->ws, "req", p, e - p); + WS_Init(req->ws, "req", p, e - p); } void @@ -352,6 +355,7 @@ SES_ReleaseReq(struct sess *sp) MPL_AssertSane(sp->req); VSL_Flush(sp->req->vsl, 0); MPL_Free(pp->mpl_req, sp->req); + sp->req->sp = NULL; sp->req = NULL; } From phk at varnish-cache.org Tue May 29 07:03:02 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Tue, 29 May 2012 09:03:02 +0200 Subject: [master] 42cf6a9 Downgrade the VCL_*_method() argument from sess to req Message-ID: commit 42cf6a926d5813e97079c6ff1ec4c05aecaa4ae2 Author: Poul-Henning Kamp Date: Tue May 29 07:02:35 2012 +0000 Downgrade the VCL_*_method() argument from sess to req diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 93e05e7..d2162a6 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -967,7 +967,7 @@ void VCL_Rel(struct VCL_conf **vcc); void VCL_Poll(void); const char *VCL_Return_Name(unsigned method); -#define VCL_MET_MAC(l,u,b) void VCL_##l##_method(struct sess *); +#define VCL_MET_MAC(l,u,b) void VCL_##l##_method(struct req *); #include "tbl/vcl_returns.h" #undef VCL_MET_MAC diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c index 81b2b3b..21f5939 100644 --- a/bin/varnishd/cache/cache_center.c +++ b/bin/varnishd/cache/cache_center.c @@ -267,7 +267,7 @@ cnt_prepresp(struct sess *sp, struct worker *wrk, struct req *req) HTTP_Setup(req->resp, req->ws, req->vsl, HTTP_Resp); RES_BuildHttp(sp); - VCL_deliver_method(sp); + VCL_deliver_method(req); switch (req->handling) { case VCL_RET_DELIVER: break; @@ -522,7 +522,7 @@ cnt_error(struct sess *sp, struct worker *wrk, struct req *req) http_PutResponse(h, req->err_reason); else http_PutResponse(h, http_StatusMessage(req->err_code)); - VCL_error_method(sp); + VCL_error_method(req); if (req->handling == VCL_RET_RESTART && req->restarts < cache_param->max_restarts) { @@ -631,7 +631,7 @@ cnt_fetch(struct sess *sp, struct worker *wrk, struct req *req) AZ(bo->do_esi); AZ(bo->do_pass); - VCL_fetch_method(sp); + VCL_fetch_method(req); if (bo->do_pass) req->objcore->flags |= OC_F_PASS; @@ -997,7 +997,7 @@ cnt_hit(struct sess *sp, struct worker *wrk, struct req *req) assert(!(req->obj->objcore->flags & OC_F_PASS)); - VCL_hit_method(sp); + VCL_hit_method(req); if (req->handling == VCL_RET_DELIVER) { //AZ(req->busyobj->bereq->ws); @@ -1171,7 +1171,7 @@ cnt_miss(struct sess *sp, struct worker *wrk, struct req *req) http_SetHeader(bo->bereq, "Accept-Encoding: gzip"); } - VCL_miss_method(sp); + VCL_miss_method(req); if (req->handling == VCL_RET_FETCH) { CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); @@ -1237,7 +1237,7 @@ cnt_pass(struct sess *sp, struct worker *wrk, struct req *req) HTTP_Setup(bo->bereq, bo->ws, bo->vsl, HTTP_Bereq); http_FilterReq(sp, HTTPH_R_PASS); - VCL_pass_method(sp); + VCL_pass_method(req); if (req->handling == VCL_RET_ERROR) { http_Teardown(bo->bereq); @@ -1297,7 +1297,7 @@ cnt_pipe(struct sess *sp, struct worker *wrk, struct req *req) HTTP_Setup(bo->bereq, bo->ws, bo->vsl, HTTP_Bereq); http_FilterReq(sp, 0); - VCL_pipe_method(sp); + VCL_pipe_method(req); if (req->handling == VCL_RET_ERROR) INCOMPL(); @@ -1395,7 +1395,7 @@ cnt_recv(struct sess *sp, const struct worker *wrk, struct req *req) http_CollectHdr(req->http, H_Cache_Control); - VCL_recv_method(sp); + VCL_recv_method(req); recv_handling = req->handling; if (cache_param->http_gzip_support && @@ -1411,7 +1411,7 @@ cnt_recv(struct sess *sp, const struct worker *wrk, struct req *req) req->sha256ctx = &sha256ctx; /* so HSH_AddString() can find it */ SHA256_Init(req->sha256ctx); - VCL_hash_method(sp); + VCL_hash_method(req); assert(req->handling == VCL_RET_HASH); SHA256_Final(req->digest, req->sha256ctx); req->sha256ctx = NULL; diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c index b68627b..6f28507 100644 --- a/bin/varnishd/cache/cache_vcl.c +++ b/bin/varnishd/cache/cache_vcl.c @@ -330,18 +330,18 @@ ccf_config_use(struct cli *cli, const char * const *av, void *priv) #define VCL_MET_MAC(func, upper, bitmap) \ void \ -VCL_##func##_method(struct sess *sp) \ +VCL_##func##_method(struct req *req) \ { \ \ - sp->req->handling = 0; \ - sp->req->cur_method = VCL_MET_ ## upper; \ - VSLb(sp->req->vsl, SLT_VCL_call, "%s", #func); \ - (void)sp->req->vcl->func##_func(sp); \ - VSLb(sp->req->vsl, SLT_VCL_return, "%s", \ - VCL_Return_Name(sp->req->handling)); \ - sp->req->cur_method = 0; \ - assert((1U << sp->req->handling) & bitmap); \ - assert(!((1U << sp->req->handling) & ~bitmap)); \ + req->handling = 0; \ + req->cur_method = VCL_MET_ ## upper; \ + VSLb(req->vsl, SLT_VCL_call, "%s", #func); \ + (void)req->vcl->func##_func(req->sp); \ + VSLb(req->vsl, SLT_VCL_return, "%s", \ + VCL_Return_Name(req->handling)); \ + req->cur_method = 0; \ + assert((1U << req->handling) & bitmap); \ + assert(!((1U << req->handling) & ~bitmap)); \ } #include "tbl/vcl_returns.h" From phk at varnish-cache.org Tue May 29 07:37:36 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Tue, 29 May 2012 09:37:36 +0200 Subject: [master] 9243e4a Stop VCL's health-polling of backend already when we discard the VCL. Message-ID: commit 9243e4a4ba009a2626d33cd3378a73d3b8f91411 Author: Poul-Henning Kamp Date: Tue May 29 07:36:53 2012 +0000 Stop VCL's health-polling of backend already when we discard the VCL. Fixes #1141 diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index d2162a6..cdd85be 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -691,6 +691,8 @@ void VCA_FailSess(struct worker *w); /* cache_backend.c */ void VBE_UseHealth(const struct director *vdi); +void VBE_DiscardHealth(const struct director *vdi); + struct vbc *VDI_GetFd(const struct director *, struct sess *sp); int VDI_Healthy(const struct director *, const struct sess *sp); diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c index 92e74da..6f2ce1f 100644 --- a/bin/varnishd/cache/cache_backend.c +++ b/bin/varnishd/cache/cache_backend.c @@ -432,6 +432,25 @@ VBE_UseHealth(const struct director *vdi) * */ +void +VBE_DiscardHealth(const struct director *vdi) +{ + struct vdi_simple *vs; + + ASSERT_CLI(); + + if (strcmp(vdi->name, "simple")) + return; + CAST_OBJ_NOTNULL(vs, vdi->priv, VDI_SIMPLE_MAGIC); + if (vs->vrt->probe == NULL) + return; + VBP_Remove(vs->backend, vs->vrt->probe); +} + +/*-------------------------------------------------------------------- + * + */ + static struct vbc * __match_proto__(vdi_getfd_f) vdi_simple_getfd(const struct director *d, struct sess *sp) { @@ -470,8 +489,6 @@ vdi_simple_fini(const struct director *d) CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC); CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC); - if (vs->vrt->probe != NULL) - VBP_Remove(vs->backend, vs->vrt->probe); VBE_DropRefVcl(vs->backend); free(vs->dir.vcl_name); vs->dir.magic = 0; diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c index 6f28507..43ef3cd 100644 --- a/bin/varnishd/cache/cache_vcl.c +++ b/bin/varnishd/cache/cache_vcl.c @@ -278,10 +278,10 @@ static void ccf_config_discard(struct cli *cli, const char * const *av, void *priv) { struct vcls *vcl; + int i; ASSERT_CLI(); - (void)av; - (void)priv; + AZ(priv); vcl = vcl_find(av[2]); if (vcl == NULL) { VCLI_SetResult(cli, CLIS_PARAM); @@ -299,6 +299,11 @@ ccf_config_discard(struct cli *cli, const char * const *av, void *priv) VSC_C_main->n_vcl_avail--; vcl->conf->discard = 1; Lck_Unlock(&vcl_mtx); + + /* Tickle this VCL's backends to give up health polling */ + for(i = 1; i < vcl->conf->ndirector; i++) + VBE_DiscardHealth(vcl->conf->director[i]); + if (vcl->conf->busy == 0) VCL_Nuke(vcl); } From tfheen at varnish-cache.org Wed May 30 09:17:20 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Wed, 30 May 2012 11:17:20 +0200 Subject: [master] 2342c8b req.url, not req.http.url Message-ID: commit 2342c8b9cd3554072f003c8b61d708ee0eb651d7 Author: Tollef Fog Heen Date: Wed May 30 11:17:17 2012 +0200 req.url, not req.http.url diff --git a/doc/sphinx/tutorial/purging.rst b/doc/sphinx/tutorial/purging.rst index 22056a7..422f9f4 100644 --- a/doc/sphinx/tutorial/purging.rst +++ b/doc/sphinx/tutorial/purging.rst @@ -88,7 +88,7 @@ Support for bans is built into Varnish and available in the CLI interface. To ban every png object belonging on example.com, issue the following command:: - ban req.http.host == "example.com" && req.http.url ~ "\.png$" + ban req.http.host == "example.com" && req.url ~ "\.png$" Quite powerful, really.