Commit 6c6ec34a authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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: http://www.varnish-cache.org/svn/trunk/varnish-cache@3061 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent cb06e78e
......@@ -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
/*-
* Copyright (c) 2006 Verdens Gang AS
* Copyright (c) 2006-2008 Linpro AS
* All rights reserved.
*
* Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
*
* 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 {"
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>"} obj.status " " obj.response {"</title>
</head>
<body>
<h1>Error "} obj.status " " obj.response {"</h1>
<p>"} obj.response {"</p>
<h3>Guru Meditation:</h3>
<p>XID: "} req.xid {"</p>
<address><a href="http://www.varnish-cache.org/">Varnish</a></address>
</body>
</html>
"};
deliver;
}
......@@ -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"
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
"<html>\n"
" <head>\n"
" <title>\"} obj.status \" \" obj.response {\"</title>\n"
" </head>\n"
" <body>\n"
" <h1>Error \"} obj.status \" \" obj.response {\"</h1>\n"
" <p>\"} obj.response {\"</p>\n"
" <h3>Guru Meditation:</h3>\n"
" <p>XID: \"} req.xid {\"</p>\n"
" <address><a href=\"http://www.varnish-cache.org/\">Varnish</a></address>\n"
" </body>\n"
"</html>\n"
"\"};\n"
" deliver;\n"
"}\n"
#include "default_vcl.h"
"" ;
/*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment