From 087a95a192841afb27ee5b471720957b960cf4bd Mon Sep 17 00:00:00 2001 From: phk Date: Mon, 4 Aug 2008 20:13:30 +0000 Subject: [PATCH] Move the default VCL code into its own text file. Generate "default_vcl.h" from this using sed(1) in the Makefile. Include default_vcl.h in mgt_vcc.c git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3061 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/Makefile.am | 11 ++ varnish-cache/bin/varnishd/default.vcl | 143 +++++++++++++++++++++++++ varnish-cache/bin/varnishd/mgt_vcc.c | 99 +---------------- 3 files changed, 155 insertions(+), 98 deletions(-) create mode 100644 varnish-cache/bin/varnishd/default.vcl diff --git a/varnish-cache/bin/varnishd/Makefile.am b/varnish-cache/bin/varnishd/Makefile.am index 30382e38..8018fc8b 100644 --- a/varnish-cache/bin/varnishd/Makefile.am +++ b/varnish-cache/bin/varnishd/Makefile.am @@ -60,6 +60,7 @@ noinst_HEADERS = \ cache_backend.h \ cache_acceptor.h \ common.h \ + default_vcl.h \ hash_slinger.h \ heritage.h \ mgt.h \ @@ -77,3 +78,13 @@ varnishd_LDADD = \ $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \ $(top_builddir)/lib/libvcl/libvcl.la \ ${DL_LIBS} ${PTHREAD_LIBS} ${NET_LIBS} ${LIBM} + +# +# Turn the default.vcl file into a C-string we can include in the program. +# +default_vcl.h: default.vcl Makefile + sed -e 's/"/\\"/g' -e 's/$$/\\n"/' -e 's/^/ "/' default.vcl > $@ + +# Explicitly record dependency +mgt_vcc.${OBJEXT}: default_vcl.h + diff --git a/varnish-cache/bin/varnishd/default.vcl b/varnish-cache/bin/varnishd/default.vcl new file mode 100644 index 00000000..758e25e1 --- /dev/null +++ b/varnish-cache/bin/varnishd/default.vcl @@ -0,0 +1,143 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2008 Linpro 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. + * + * $Id$ + * + * The default VCL code. + * + * NB! You do NOT need to copy & paste all of this into your won vcl code, + * if you do not handle one of the functions, the compiler will automaticall + * fall back to the default code. + * + * This code will be prefixed with a backend declaration built from the + * -b argument. + */ + +sub vcl_recv { + if (req.request != "GET" && + req.request != "HEAD" && + req.request != "PUT" && + req.request != "POST" && + req.request != "TRACE" && + req.request != "OPTIONS" && + req.request != "DELETE") { + /* Non-RFC2616 or CONNECT which is weird. */ + pipe; + } + if (req.http.Expect) { + /* Expect is just too hard at present. */ + pipe; + } + if (req.request != "GET" && req.request != "HEAD") { + /* We only deal with GET and HEAD by default */ + pass; + } + if (req.http.Authorization || req.http.Cookie) { + /* Not cacheable by default */ + pass; + } + lookup; +} + +sub vcl_pipe { + pipe; +} + +sub vcl_pass { + pass; +} + +sub vcl_hash { + set req.hash += req.url; + if (req.http.host) { + set req.hash += req.http.host; + } else { + set req.hash += server.ip; + } + hash; +} + +sub vcl_hit { + if (!obj.cacheable) { + pass; + } + deliver; +} + +sub vcl_miss { + fetch; +} + +sub vcl_fetch { + if (!obj.cacheable) { + pass; + } + if (obj.http.Set-Cookie) { + pass; + } + set obj.prefetch = -30s; + deliver; +} + +sub vcl_deliver { + deliver; +} + +sub vcl_discard { + discard; +} + +sub vcl_prefetch { + fetch; +} + +sub vcl_timeout { + discard; +} + +sub vcl_error { + set obj.http.Content-Type = "text/html; charset=utf-8"; + synthetic {" + + + + + "} obj.status " " obj.response {" + + +

Error "} obj.status " " obj.response {"

+

"} obj.response {"

+

Guru Meditation:

+

XID: "} req.xid {"

+
Varnish
+ + +"}; + deliver; +} diff --git a/varnish-cache/bin/varnishd/mgt_vcc.c b/varnish-cache/bin/varnishd/mgt_vcc.c index 2573a5a8..673fc8cb 100644 --- a/varnish-cache/bin/varnishd/mgt_vcc.c +++ b/varnish-cache/bin/varnishd/mgt_vcc.c @@ -79,104 +79,7 @@ char *mgt_cc_cmd; * Keep this in synch with man/vcl.7 and etc/default.vcl! */ static const char *default_vcl = - "sub vcl_recv {\n" - " if (req.request != \"GET\" &&\n" - " req.request != \"HEAD\" &&\n" - " req.request != \"PUT\" &&\n" - " req.request != \"POST\" &&\n" - " req.request != \"TRACE\" &&\n" - " req.request != \"OPTIONS\" &&\n" - " req.request != \"DELETE\") {\n" - " /* Non-RFC2616 or CONNECT which is weird. */\n" - " pipe;\n" - " }\n" - " if (req.http.Expect) {\n" - " /* Expect is just too hard at present. */\n" - " pipe;\n" - " }\n" - " if (req.request != \"GET\" && req.request != \"HEAD\") {\n" - " /* We only deal with GET and HEAD by default */\n" - " pass;\n" - " }\n" - " if (req.http.Authorization || req.http.Cookie) {\n" - " /* Not cacheable by default */\n" - " pass;\n" - " }\n" - " lookup;\n" - "}\n" - "\n" - "sub vcl_pipe {\n" - " pipe;\n" - "}\n" - "\n" - "sub vcl_pass {\n" - " pass;\n" - "}\n" - "\n" - "sub vcl_hash {\n" - " set req.hash += req.url;\n" - " if (req.http.host) {\n" - " set req.hash += req.http.host;\n" - " } else {\n" - " set req.hash += server.ip;\n" - " }\n" - " hash;\n" - "}\n" - "\n" - "sub vcl_hit {\n" - " if (!obj.cacheable) {\n" - " pass;\n" - " }\n" - " deliver;\n" - "}\n" - "\n" - "sub vcl_miss {\n" - " fetch;\n" - "}\n" - "\n" - "sub vcl_fetch {\n" - " if (!obj.cacheable) {\n" - " pass;\n" - " }\n" - " if (obj.http.Set-Cookie) {\n" - " pass;\n" - " }\n" - " set obj.prefetch = -30s;" - " deliver;\n" - "}\n" - "sub vcl_deliver {\n" - " deliver;\n" - "}\n" - "sub vcl_discard {\n" - " discard;\n" - "}\n" - "sub vcl_prefetch {\n" - " fetch;\n" - "}\n" - "sub vcl_timeout {\n" - " discard;\n" - "}\n" - "sub vcl_error {\n" - " set obj.http.Content-Type = \"text/html; charset=utf-8\";" - " synthetic {\"\n" - "\n" - "\n" - "\n" - " \n" - " \"} obj.status \" \" obj.response {\"\n" - " \n" - " \n" - "

Error \"} obj.status \" \" obj.response {\"

\n" - "

\"} obj.response {\"

\n" - "

Guru Meditation:

\n" - "

XID: \"} req.xid {\"

\n" - "
Varnish
\n" - " \n" - "\n" - "\"};\n" - " deliver;\n" - "}\n" +#include "default_vcl.h" "" ; /* -- 2.39.5