[master] 3a308c3 Rename default.vcl to builtin.vcl.

Lasse Karstensen lkarsten at varnish-software.com
Mon Jan 27 12:07:05 CET 2014


commit 3a308c36d471f38e338502253e198bac98128774
Author: Lasse Karstensen <lkarsten at varnish-software.com>
Date:   Mon Jan 27 11:20:23 2014 +0100

    Rename default.vcl to builtin.vcl.
    
    The default.vcl name was thought up in 2007 and have been a point of confusion
    since.
    
    New users take the old default VCL, uncomment what they think makes sense, and
    always end with return(lookup) because that seems to be needed. But it isn't,
    and the defaults in the built-in VCL are much better at handling all things
    they haven't learned about yet.

diff --git a/.gitignore b/.gitignore
index f545294..78cdba5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -44,8 +44,8 @@ cscope.*out
 /varnishapi-uninstalled.pc
 
 # Default vcl made from bin/varnishd/default.vcl
-/bin/varnishd/default_vcl.h
-/etc/default.vcl
+/bin/varnishd/builtin_vcl.h
+/etc/builtin.vcl
 
 # Various auto-generated code snippets
 /include/vcl.h
diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am
index 9d281f1..e0a8461 100644
--- a/bin/varnishd/Makefile.am
+++ b/bin/varnishd/Makefile.am
@@ -93,7 +93,7 @@ noinst_HEADERS = \
 	cache/cache_backend.h \
 	cache/cache_esi.h \
 	common/heritage.h \
-	default_vcl.h \
+	builtin_vcl.h \
 	hash/hash_slinger.h \
 	mgt/mgt.h \
 	mgt/mgt_cli.h \
@@ -126,26 +126,26 @@ varnishd_LDADD = \
 	@PCRE_LIBS@ \
 	${DL_LIBS} ${PTHREAD_LIBS} ${NET_LIBS} ${LIBM} ${LIBUMEM}
 
-EXTRA_DIST = default.vcl
-DISTCLEANFILES = default_vcl.h
+EXTRA_DIST = builtin.vcl
+DISTCLEANFILES = builtin_vcl.h
 
 #
-# Turn the default.vcl file into a C-string we can include in the program.
+# Turn the builtin.vcl file into a C-string we can include in the program.
 #
-default_vcl.h:	default.vcl
+builtin_vcl.h:	builtin.vcl
 	echo '/*' > $@
 	echo ' * NB:  This file is machine generated, DO NOT EDIT!' >> $@
 	echo ' *' >> $@
-	echo ' * Edit default.vcl instead and run make' >> $@
+	echo ' * Edit builtin.vcl instead and run make' >> $@
 	echo ' *' >> $@
 	echo ' */' >> $@
 	echo '' >> $@
 	sed -e 's/"/\\"/g' \
 	    -e 's/$$/\\n"/' \
-	    -e 's/^/ "/' $(srcdir)/default.vcl >> $@
+	    -e 's/^/ "/' $(srcdir)/builtin.vcl >> $@
 
 # Explicitly record dependency
-mgt/mgt_vcc.c:	default_vcl.h
+mgt/mgt_vcc.c:	builtin_vcl.h
 
 varnishd.1: $(top_srcdir)/doc/sphinx/reference/varnishd.rst
 if HAVE_RST2MAN
diff --git a/bin/varnishd/Makefile.phk b/bin/varnishd/Makefile.phk
index d0ee858..1cbd5c2 100644
--- a/bin/varnishd/Makefile.phk
+++ b/bin/varnishd/Makefile.phk
@@ -95,7 +95,7 @@ LD_ADD	+= -lm
 
 RST_MAN += $(TOPDIR)/doc/sphinx/reference/varnishd.rst
 
-MADE_FILES += default_vcl.h
+MADE_FILES += builtin_vcl.h
 
 TODO_INSTALL += install_etc
 
@@ -103,20 +103,20 @@ TOPDIR  = $(CURDIR)/../..
 include $(TOPDIR)/Makefile.inc.phk
 
 #
-# Turn the default.vcl file into a C-string we can include in the program.
+# Turn the builtin.vcl file into a C-string we can include in the program.
 #
-default_vcl.h:	default.vcl
+builtint_vcl.h:	builtin.vcl
 	echo '/*' > $@
 	echo ' * NB:  This file is machine generated, DO NOT EDIT!' >> $@
 	echo ' *' >> $@
-	echo ' * Edit default.vcl instead and run make' >> $@
+	echo ' * Edit builtin.vcl instead and run make' >> $@
 	echo ' *' >> $@
 	echo ' */' >> $@
 	echo '' >> $@
 	sed -e 's/"/\\"/g' \
 	    -e 's/$$/\\n"/' \
-	    -e 's/^/ "/' default.vcl >> $@
+	    -e 's/^/ "/' builtin.vcl >> $@
 
 .PHONY: install_etc
-install_etc: default_vcl.h
-	@cp default_vcl.h $(INSTALL_BASE)/etc/
+install_etc: builtin_vcl.h
+	@cp builtin_vcl.h $(INSTALL_BASE)/etc/
diff --git a/bin/varnishd/builtin.vcl b/bin/varnishd/builtin.vcl
new file mode 100644
index 0000000..3a723e3
--- /dev/null
+++ b/bin/varnishd/builtin.vcl
@@ -0,0 +1,185 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2014 Varnish Software 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.
+ *
+
+ *
+ * The built-in (previously called default) VCL code.
+ *
+ * NB! You do NOT need to copy & paste all of these functions into your
+ * own vcl code, if you do not provide a definition of one of these
+ * functions, the compiler will automatically fall back to the default
+ * code from this file.
+ *
+ * This code will be prefixed with a backend declaration built from the
+ * -b argument.
+ */
+
+vcl 4.0;
+
+sub vcl_recv {
+    if (req.restarts == 0) {
+	if (req.http.x-forwarded-for) {
+	    set req.http.X-Forwarded-For =
+		req.http.X-Forwarded-For + ", " + client.ip;
+	} else {
+	    set req.http.X-Forwarded-For = client.ip;
+	}
+    }
+    if (req.method != "GET" &&
+      req.method != "HEAD" &&
+      req.method != "PUT" &&
+      req.method != "POST" &&
+      req.method != "TRACE" &&
+      req.method != "OPTIONS" &&
+      req.method != "DELETE") {
+        /* Non-RFC2616 or CONNECT which is weird. */
+        return (pipe);
+    }
+    if (req.method != "GET" && req.method != "HEAD") {
+        /* We only deal with GET and HEAD by default */
+        return (pass);
+    }
+    if (req.http.Authorization || req.http.Cookie) {
+        /* Not cacheable by default */
+        return (pass);
+    }
+    return (hash);
+}
+
+sub vcl_pipe {
+    # Note that only the first request to the backend will have
+    # X-Forwarded-For set.  If you use X-Forwarded-For and want to
+    # have it set for all requests, make sure to have:
+    # set bereq.http.connection = "close";
+    # here.  It is not set by default as it might break some broken web
+    # applications, like IIS with NTLM authentication.
+    return (pipe);
+}
+
+sub vcl_pass {
+    return (fetch);
+}
+
+sub vcl_hash {
+    hash_data(req.url);
+    if (req.http.host) {
+        hash_data(req.http.host);
+    } else {
+        hash_data(server.ip);
+    }
+    return (lookup);
+}
+
+sub vcl_purge {
+    return (error(200, "Purged"));
+}
+
+sub vcl_hit {
+    if (obj.ttl >= 0s) {
+	// A pure unadultered hit, deliver it
+	return (deliver);
+    }
+    if (obj.ttl + obj.grace > 0s) {
+	// Object is in grace, delive it
+	// Automatically triggers a background fetch
+	return (deliver);
+    }
+    // fetch & deliver once we get the result
+    return (fetch);
+}
+
+sub vcl_miss {
+    return (fetch);
+}
+
+
+sub vcl_backend_fetch {
+    return (fetch);
+}
+
+sub vcl_backend_response {
+    if (beresp.ttl <= 0s ||
+        beresp.http.Set-Cookie ||
+        beresp.http.Surrogate-control ~ "no-store" ||
+        (!beresp.http.Surrogate-Control &&
+          beresp.http.Cache-Control ~ "no-cache|no-store|private") ||
+        beresp.http.Vary == "*") {
+		/*
+		 * Mark as "Hit-For-Pass" for the next 2 minutes
+		 */
+		set beresp.ttl = 120 s;
+		set beresp.uncacheable = true;
+    }
+    return (deliver);
+}
+
+sub vcl_deliver {
+    /*
+     * These two write to the stored object causing extra page faults
+     * Enable them only if you need them.
+     *
+     * set obj.hits = obj.hits + 1;
+     * set obj.last_use = now;
+     */
+    return (deliver);
+}
+
+/*
+ * We can come here "invisibly" with the following errors:  413, 417 & 503
+ */
+sub vcl_error {
+    set obj.http.Content-Type = "text/html; charset=utf-8";
+    set obj.http.Retry-After = "5";
+    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>
+    <hr>
+    <p>Varnish cache server</p>
+  </body>
+</html>
+"};
+    return (deliver);
+}
+
+sub vcl_init {
+	return (ok);
+}
+
+sub vcl_fini {
+	return (ok);
+}
diff --git a/bin/varnishd/default.vcl b/bin/varnishd/default.vcl
deleted file mode 100644
index 8e8fa26..0000000
--- a/bin/varnishd/default.vcl
+++ /dev/null
@@ -1,185 +0,0 @@
-/*-
- * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2014 Varnish Software 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.
- *
-
- *
- * The default VCL code.
- *
- * NB! You do NOT need to copy & paste all of these functions into your
- * own vcl code, if you do not provide a definition of one of these
- * functions, the compiler will automatically fall back to the default
- * code from this file.
- *
- * This code will be prefixed with a backend declaration built from the
- * -b argument.
- */
-
-vcl 4.0;
-
-sub vcl_recv {
-    if (req.restarts == 0) {
-	if (req.http.x-forwarded-for) {
-	    set req.http.X-Forwarded-For =
-		req.http.X-Forwarded-For + ", " + client.ip;
-	} else {
-	    set req.http.X-Forwarded-For = client.ip;
-	}
-    }
-    if (req.method != "GET" &&
-      req.method != "HEAD" &&
-      req.method != "PUT" &&
-      req.method != "POST" &&
-      req.method != "TRACE" &&
-      req.method != "OPTIONS" &&
-      req.method != "DELETE") {
-        /* Non-RFC2616 or CONNECT which is weird. */
-        return (pipe);
-    }
-    if (req.method != "GET" && req.method != "HEAD") {
-        /* We only deal with GET and HEAD by default */
-        return (pass);
-    }
-    if (req.http.Authorization || req.http.Cookie) {
-        /* Not cacheable by default */
-        return (pass);
-    }
-    return (hash);
-}
-
-sub vcl_pipe {
-    # Note that only the first request to the backend will have
-    # X-Forwarded-For set.  If you use X-Forwarded-For and want to
-    # have it set for all requests, make sure to have:
-    # set bereq.http.connection = "close";
-    # here.  It is not set by default as it might break some broken web
-    # applications, like IIS with NTLM authentication.
-    return (pipe);
-}
-
-sub vcl_pass {
-    return (fetch);
-}
-
-sub vcl_hash {
-    hash_data(req.url);
-    if (req.http.host) {
-        hash_data(req.http.host);
-    } else {
-        hash_data(server.ip);
-    }
-    return (lookup);
-}
-
-sub vcl_purge {
-    return (error(200, "Purged"));
-}
-
-sub vcl_hit {
-    if (obj.ttl >= 0s) {
-	// A pure unadultered hit, deliver it
-	return (deliver);
-    }
-    if (obj.ttl + obj.grace > 0s) {
-	// Object is in grace, delive it
-	// Automatically triggers a background fetch
-	return (deliver);
-    }
-    // fetch & deliver once we get the result
-    return (fetch);
-}
-
-sub vcl_miss {
-    return (fetch);
-}
-
-
-sub vcl_backend_fetch {
-    return (fetch);
-}
-
-sub vcl_backend_response {
-    if (beresp.ttl <= 0s ||
-        beresp.http.Set-Cookie ||
-        beresp.http.Surrogate-control ~ "no-store" ||
-        (!beresp.http.Surrogate-Control &&
-          beresp.http.Cache-Control ~ "no-cache|no-store|private") ||
-        beresp.http.Vary == "*") {
-		/*
-		 * Mark as "Hit-For-Pass" for the next 2 minutes
-		 */
-		set beresp.ttl = 120 s;
-		set beresp.uncacheable = true;
-    }
-    return (deliver);
-}
-
-sub vcl_deliver {
-    /*
-     * These two write to the stored object causing extra page faults
-     * Enable them only if you need them.
-     *
-     * set obj.hits = obj.hits + 1;
-     * set obj.last_use = now;
-     */
-    return (deliver);
-}
-
-/*
- * We can come here "invisibly" with the following errors:  413, 417 & 503
- */
-sub vcl_error {
-    set obj.http.Content-Type = "text/html; charset=utf-8";
-    set obj.http.Retry-After = "5";
-    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>
-    <hr>
-    <p>Varnish cache server</p>
-  </body>
-</html>
-"};
-    return (deliver);
-}
-
-sub vcl_init {
-	return (ok);
-}
-
-sub vcl_fini {
-	return (ok);
-}
diff --git a/bin/varnishd/mgt/mgt_vcc.c b/bin/varnishd/mgt/mgt_vcc.c
index d3e81de..09e4eb4 100644
--- a/bin/varnishd/mgt/mgt_vcc.c
+++ b/bin/varnishd/mgt/mgt_vcc.c
@@ -71,8 +71,8 @@ static struct vcc *vcc;
 
 /*--------------------------------------------------------------------*/
 
-static const char * const default_vcl =
-#include "default_vcl.h"
+static const char * const builtin_vcl =
+#include "builtin_vcl.h"
     ""	;
 
 /*--------------------------------------------------------------------
@@ -488,7 +488,7 @@ mgt_vcc_init(void)
 
 	vcc = VCC_New();
 	AN(vcc);
-	VCC_Default_VCL(vcc, default_vcl);
+	VCC_Default_VCL(vcc, builtin_vcl);
 	AZ(atexit(mgt_vcc_atexit));
 }
 
diff --git a/doc/sphinx/reference/vcl.rst b/doc/sphinx/reference/vcl.rst
index 8a3ee2c..d769e81 100644
--- a/doc/sphinx/reference/vcl.rst
+++ b/doc/sphinx/reference/vcl.rst
@@ -922,7 +922,7 @@ specified:
    .port = "http";
   }
 
-.. include:: ../../../bin/varnishd/default.vcl
+.. include:: ../../../bin/varnishd/builtin.vcl
   :literal:
 
 The following example shows how to support multiple sites running on
diff --git a/etc/Makefile.am b/etc/Makefile.am
index 2fb4d38..af964e9 100644
--- a/etc/Makefile.am
+++ b/etc/Makefile.am
@@ -1,23 +1,11 @@
 #
 
-DISTCLEANFILES = default.vcl
+DISTCLEANFILES = builtin.vcl
 
-dist_varnishconf_DATA = default.vcl
+dist_varnishconf_DATA = builtin.vcl
 
-default.vcl:	$(top_srcdir)/bin/varnishd/default.vcl
-	( printf "vcl 4.0;\nThis is a basic VCL configuration file for varnish.  See the vcl(7)\n\
-man page for details on VCL syntax and semantics.\n\
-\n\
-Default backend definition.  Set this to point to your content\n\
-server.\n\
-\n\
-backend default {\n\
-    .host = \"127.0.0.1\";\n\
-    .port = \"8080\";\n\
-}\n\
-\n\
-Below is a commented-out copy of the default VCL logic.  If you\n\
-redefine any of these subroutines, the built-in logic will be\n\
-appended to your code.\n" ; \
-	sed -n '/vcl_recv/,$$p' $(top_srcdir)/bin/varnishd/default.vcl ) | \
-	sed 's/^\(.*\)$$/# \1/' > default.vcl
+builtin.vcl:	$(top_srcdir)/bin/varnishd/builtin.vcl
+	( printf "This is the VCL configuration Varnish will automatically append to your VCL\nfile during compilation/loading. See the vcl(7) man page for details on syntax\nand semantics.\n\
+New users is recommended to use the example.vcl file as a starting point.\n\n";\
+	sed -n '/vcl_recv/,$$p' $(top_srcdir)/bin/varnishd/builtin.vcl ) | \
+	sed 's/^\(.*\)$$/# \1/' > builtin.vcl
diff --git a/man/Makefile.am b/man/Makefile.am
index 56b0a52..1ed3a5d 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -12,7 +12,7 @@ dist_man_MANS = vcl.7 varnish-cli.7 varnish-counters.7 vsl.7 vsl-query.7
 MAINTAINERCLEANFILES = $(dist_man_MANS)
 
 vcl.7: $(top_srcdir)/doc/sphinx/reference/vcl.rst \
-	$(top_srcdir)/bin/varnishd/default.vcl
+	$(top_srcdir)/bin/varnishd/builtin.vcl
 if HAVE_RST2MAN
 	${RST2MAN} $(top_srcdir)/doc/sphinx/reference/vcl.rst $@
 else



More information about the varnish-commit mailing list