r3061 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Mon Aug 4 22:13:30 CEST 2008


Author: phk
Date: 2008-08-04 22:13:30 +0200 (Mon, 04 Aug 2008)
New Revision: 3061

Added:
   trunk/varnish-cache/bin/varnishd/default.vcl
Modified:
   trunk/varnish-cache/bin/varnishd/Makefile.am
   trunk/varnish-cache/bin/varnishd/mgt_vcc.c
Log:
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


Modified: trunk/varnish-cache/bin/varnishd/Makefile.am
===================================================================
--- trunk/varnish-cache/bin/varnishd/Makefile.am	2008-08-01 12:44:53 UTC (rev 3060)
+++ trunk/varnish-cache/bin/varnishd/Makefile.am	2008-08-04 20:13:30 UTC (rev 3061)
@@ -60,6 +60,7 @@
 	cache_backend.h \
 	cache_acceptor.h \
 	common.h \
+	default_vcl.h \
 	hash_slinger.h \
 	heritage.h \
 	mgt.h \
@@ -77,3 +78,13 @@
 	$(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
+

Added: trunk/varnish-cache/bin/varnishd/default.vcl
===================================================================
--- trunk/varnish-cache/bin/varnishd/default.vcl	                        (rev 0)
+++ trunk/varnish-cache/bin/varnishd/default.vcl	2008-08-04 20:13:30 UTC (rev 3061)
@@ -0,0 +1,143 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2008 Linpro AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at 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;
+}


Property changes on: trunk/varnish-cache/bin/varnishd/default.vcl
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_vcc.c	2008-08-01 12:44:53 UTC (rev 3060)
+++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c	2008-08-04 20:13:30 UTC (rev 3061)
@@ -79,104 +79,7 @@
  * 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"
     ""	;
 
 /*




More information about the varnish-commit mailing list