[4.0] 2ebf017 Clean up for 4.0 syntax.

Lasse Karstensen lkarsten at varnish-software.com
Tue Apr 1 15:09:52 CEST 2014


commit 2ebf017d5af8104e59b8876f3b3bf720c44da4bb
Author: Lasse Karstensen <lkarsten at varnish-software.com>
Date:   Fri Mar 21 14:43:48 2014 +0100

    Clean up for 4.0 syntax.

diff --git a/doc/sphinx/reference/vcl.rst b/doc/sphinx/reference/vcl.rst
index 942d1ac..c71577b 100644
--- a/doc/sphinx/reference/vcl.rst
+++ b/doc/sphinx/reference/vcl.rst
@@ -12,36 +12,19 @@ DESCRIPTION
 ===========
 
 The VCL language is a small domain-specific language designed to be
-used to define request handling and document caching policies for
+used to describe request handling and document caching policies for
 Varnish Cache.
 
 When a new configuration is loaded, the varnishd management process
 translates the VCL code to C and compiles it to a shared object which
-is then dynamically linked into the server process.
+is then loaded into the server process.
 
 This document focuses on the syntax of the VCL language. For a full
 description of syntax and semantics, with ample examples, please see
-the users guide at https://www.varnish-cache.org/docs/
-
-VCL consists of the following elements:
- * Operators
- * Conditionals
- * Strings, booleans, time, duration, ints
- * Regular expressions
-
-In addition VCL has the following constructs:
- * Include
- * Backend definitions
- * Probes
- * Access control lists - ACLs
- * Import statement
- * Functions
- * Subroutines
+the online documentation at https://www.varnish-cache.org/docs/ .
 
-Note that are no loops or iterators of any kind in VCL.
-
-Each VCL file must start by declaring its version. For Varnish 4.0 you
-must include a "vcl 4.0;" at the top of the file.
+Starting with Varnish 4.0, each VCL file must start by declaring its version
+with a special "vcl 4.0;" marker at the top of the file.
 
 
 Operators
@@ -62,35 +45,39 @@ The following operators are available in VCL:
     Negation.
 
   &&
-    Logical and
+    Logical and.
 
   ||
-    Logical or
+    Logical or.
 
 
 Conditionals
 ------------
 
-VCL has *if* statements.
+VCL has *if* and *else* statements. Nested logic can be implemented
+with the *elseif* statement. (*elsif*/*elif*/*else if* is equivalent.)
 
+Note that are no loops or iterators of any kind in VCL.
 
-Strings, booleans, time, duration and ints
-------------------------------------------
+
+Strings, booleans, time, duration and integers
+----------------------------------------------
 
 These are the data types in Varnish. You can *set* or *unset* these.
 
 Example::
 
-  set req.http.user-agent = "unknown";
+  set req.http.User-Agent = "unknown";
+  unset req.http.Range;
 
 
 Strings
 ~~~~~~~
 
-Basic strings are enclosed in " ... ", and may not contain
+Basic strings are enclosed in double quotes (" ... "), and may not contain
 newlines. Long strings are enclosed in {" ... "}. They may contain any
-character including ", newline and other control characters except for
-the NUL (0x00) character
+character including single double quotes ("), newline and other control
+characters except for the NUL (0x00) character.
 
 Booleans
 ~~~~~~~~
@@ -107,7 +94,8 @@ formatted string.
 Durations
 ---------
 
-Durations are defined by a number and a designation. The number can be a real so 1.5w is allowed.
+Durations are defined by a number and a designation. The number can be a real
+so 1.5w is allowed.
 
   ms
     milliseconds
@@ -128,14 +116,14 @@ Durations are defined by a number and a designation. The number can be a real so
     weeks
 
 
-Ints
-----
+Integers
+--------
 
 Certain fields are integers, used as expected. In string context they
 return a string.
 
-Reals
------
+Real numbers
+------------
 
 VCL understands real numbers. As with integers, when used in a string
 context they will return a string.
@@ -144,12 +132,11 @@ context they will return a string.
 Regular Expressions
 -------------------
 
-Varnish uses PCRE - Perl-compatible regular expressions. For a
-complete description of PCRE please see the pcre(3) man page.
+Varnish uses Perl-compatible regular expressions (PCRE). For a
+complete description please see the 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::
+To send flags to the PCRE engine, such as to do case insensitive matching, add
+the flag within parens following a question mark, like this::
 
     # If host is NOT example dot com..
     if (req.http.host !~ "(?i)example.com$") {
@@ -162,22 +149,35 @@ Include statement
 
 To include a VCL file in another file use the include keyword::
 
-  include "foo.vcl";
+    include "foo.vcl";
+
+
+Import statement
+----------------
+
+The *import* statement is used to load Varnish Modules (VMODs.)
+
+Example::
+
+    import std;
+    sub vcl_recv {
+        std.log("foo");
+    }
+
 
 
 Backend definition
 ------------------
 
-A backend declaration creates and initializes a named backend
-object. A declaration start with the keyword *backend* followed by the
-name of the backend. The actual declaration is in curly brackets, in a
-key/value fashion.::
+A backend declaration creates and initialises a named backend object. A
+declaration start with the keyword *backend* followed by the name of the
+backend. The actual declaration is in curly brackets, in a key/value fashion.::
 
     backend name {
         .attribute = "value";
     }
 
-The only mandatory attribute is host. The attributes will inherit
+The only mandatory attribute is *host*. The attributes will inherit
 their defaults from the global parameters. The following attributes
 are available:
 
@@ -233,9 +233,9 @@ There are no mandatory options. These are the options you can set:
 
   expected_response
     The expected HTTP response code. Defaults to 200.
-            
+
   timeout
-    The timeout for the probe. Default it 2s.
+    The timeout for the probe. Default is 2s.
 
   interval
     How often the probe is run. Default is 5s.
@@ -245,10 +245,11 @@ There are no mandatory options. These are the options you can set:
     starts. Defaults to the value of threshold - 1. In this case, the
     backend starts as sick and requires one single poll to be
     considered healthy.
-            
+
   window
-    How many of the latest polls we examine to determine backend health. Defaults to 8.
-            
+    How many of the latest polls we examine to determine backend health.
+    Defaults to 8.
+
   threshold
     How many of the polls in .window must have succeeded for us to
     consider the backend healthy. If this is set to more than or equal
@@ -258,68 +259,82 @@ There are no mandatory options. These are the options you can set:
     threshold - 1.
 
 
-ACLs
-----
+Access Control List (ACL)
+-------------------------
 
-An ACL declaration creates and initializes a named access control list
-which can later be used to match client addresses::
+An Access Control List (ACL) declaration creates and initialises a named access
+control list which can later be used to match client addresses::
 
-    acl local {
+    acl localnetwork {
         "localhost";    # myself
         "192.0.2.0"/24; # and everyone on the local network
-        ! "192.0.2.23"; # except for the dialin router
+        ! "192.0.2.23"; # except for the dial-in router
     }
 
 If an ACL entry specifies a host name which Varnish is unable to
-resolve, it will match any address it is compared to.  Consequently,
+resolve, it will match any address it is compared to. Consequently,
 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
+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::
 
-    if (client.ip ~ local) {
+    if (client.ip ~ localnetwork) {
         return (pipe);
     }
 
 
+VCL objects
+-----------
+
+A VCL object can be made with the *new* keyword.
+
+Example::
+
+    sub vcl_init {
+        new b = directors.round_robin()
+        b.add_backend(node1);
+    }
+
+
 Subroutines
 -----------
 
 A subroutine is used to group code for legibility or reusability::
 
     sub pipe_if_local {
-        if (client.ip ~ local) {
+        if (client.ip ~ localnetwork) {
             return (pipe);
         }
     }
 
 Subroutines in VCL do not take arguments, nor do they return
-values. The built in subroutines all have names beginning with vcl_,
+values. The built in subroutines all have names beginning with vcl\_,
 which is reserved.
 
 To call a subroutine, use the call keyword followed by the subroutine's name::
 
-    call pipe_if_local;
+    sub vcl_recv {
+        call pipe_if_local;
+    }
 
 Return statements
 ~~~~~~~~~~~~~~~~~
 
-The subroutine executions ends when a return(*action*) statement is
-made. The *action* specifies how execution should proceed. The context
-defines which actions are available. See the user guide for information
-on what actions are available where.
+The ongoing vcl\_* subroutine execution ends when a return(*action*) statement
+is made.
+
+The *action* specifies how execution should proceed. The context defines
+which actions are available.
 
 Multiple subroutines
 ~~~~~~~~~~~~~~~~~~~~
 
-If multiple subroutines with the name of one of the builtin
-ones are defined, they are concatenated in the order in which they
-appear in the source.
-
-The default versions distributed with Varnish will be implicitly
-concatenated.
+If multiple subroutines with the name of one of the built-in ones are defined,
+they are concatenated in the order in which they appear in the source.
 
+The built-in VCL distributed with Varnish will be implicitly concatenated
+when the VCL is compiled.
 
 
 Variables
@@ -338,11 +353,35 @@ Functions
 The following built-in functions are available:
 
 ban(expression)
-  Bans all objects in cache that match the expression.
+  Invalidates all objects in cache that match the expression with the
+  ban mechanism.
+
+call(subroutine)
+  Run a VCL subroutine within the current scope.
+
+hash_data(input)
+  Adds an input to the hash input. In the built-in VCL hash_data()
+  is called on the host and URL of the *request*. Available in vcl_hash.
+
+new()
+  Instanciate a new VCL object. Available in vcl_init.
+
+purge()
+  Invalidate all variants of the current object using purge. Available in 
+  vcl_miss and vcl_hit.
 
-hash_data(str)
-  Adds a string to the hash input. In the built-in VCL hash_data()
-  is called on the host and URL of the *request*.
+return()
+  End execution of the current VCL subroutine, and continue to the next step
+  in the request handling state machine.
+
+rollback()
+  Restore request HTTP headers to their original state.
+
+synthetic(STRING)
+  Prepare a synthetic response body containing the STRING. Available in
+  vcl_synth and vcl_backend_error.
+
+.. list above comes from struct action_table[] in vcc_action.c.
 
 regsub(str, regex, sub)
   Returns a copy of str with the first occurrence of the regular
@@ -354,11 +393,13 @@ regsub(str, regex, sub)
 regsuball(str, regex, sub)
   As regsub() but this replaces all occurrences.
 
+.. regsub* is in vcc_expr.c
+
 
 EXAMPLES
 ========
 
-For examples, please see the guide guide.
+For examples, please see the online documentation.
 
 SEE ALSO
 ========
@@ -373,7 +414,7 @@ HISTORY
 VCL was developed by Poul-Henning Kamp in cooperation with Verdens
 Gang AS, Redpill Linpro and Varnish Software.  This manual page is
 written by Per Buer, Poul-Henning Kamp, Martin Blix Grydeland,
-Kristian Lyngstøl and possibly others.
+Kristian Lyngstøl, Lasse Karstensen and possibly others.
 
 COPYRIGHT
 =========



More information about the varnish-commit mailing list