root/trunk/varnish-cache/bin/varnishd/default.vcl

Revision 5133, 4.1 KB (checked in by phk, 7 days ago)

Push the new expressions into all other actions.

Get precedence of the implicit cast to STRING right.

  • Property svn:keywords set to Id
Line 
1/*-
2 * Copyright (c) 2006 Verdens Gang AS
3 * Copyright (c) 2006-2009 Linpro AS
4 * All rights reserved.
5 *
6 * Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * $Id$
30 *
31 * The default VCL code.
32 *
33 * NB! You do NOT need to copy & paste all of these functions into your
34 * own vcl code, if you do not provide a definition of one of these
35 * functions, the compiler will automatically fall back to the default
36 * code from this file.
37 *
38 * This code will be prefixed with a backend declaration built from the
39 * -b argument.
40 */
41
42sub vcl_recv {
43    if (req.restarts == 0) {
44        if (req.http.x-forwarded-for) {
45            set req.http.X-Forwarded-For =
46                req.http.X-Forwarded-For + ", " + client.ip;
47        } else {
48            set req.http.X-Forwarded-For = client.ip;
49        }
50    }
51    if (req.request != "GET" &&
52      req.request != "HEAD" &&
53      req.request != "PUT" &&
54      req.request != "POST" &&
55      req.request != "TRACE" &&
56      req.request != "OPTIONS" &&
57      req.request != "DELETE") {
58        /* Non-RFC2616 or CONNECT which is weird. */
59        return (pipe);
60    }
61    if (req.request != "GET" && req.request != "HEAD") {
62        /* We only deal with GET and HEAD by default */
63        return (pass);
64    }
65    if (req.http.Authorization || req.http.Cookie) {
66        /* Not cacheable by default */
67        return (pass);
68    }
69    return (lookup);
70}
71
72sub vcl_pipe {
73    # Note that only the first request to the backend will have
74    # X-Forwarded-For set.  If you use X-Forwarded-For and want to
75    # have it set for all requests, make sure to have:
76    # set req.http.connection = "close";
77    # here.  It is not set by default as it might break some broken web
78    # applications, like IIS with NTLM authentication.
79    return (pipe);
80}
81
82sub vcl_pass {
83    return (pass);
84}
85
86sub vcl_hash {
87    hash_data(req.url);
88    if (req.http.host) {
89        hash_data(req.http.host);
90    } else {
91        hash_data(server.ip);
92    }
93    return (hash);
94}
95
96sub vcl_hit {
97    if (!obj.cacheable) {
98        return (pass);
99    }
100    return (deliver);
101}
102
103sub vcl_miss {
104    return (fetch);
105}
106
107sub vcl_fetch {
108    if (!beresp.cacheable) {
109        return (pass);
110    }
111    if (beresp.http.Set-Cookie) {
112        return (pass);
113    }
114    return (deliver);
115}
116
117sub vcl_deliver {
118    return (deliver);
119}
120
121sub vcl_error {
122    set obj.http.Content-Type = "text/html; charset=utf-8";
123    synthetic {"
124<?xml version="1.0" encoding="utf-8"?>
125<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
126 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
127<html>
128  <head>
129    <title>"} + obj.status + " " + obj.response + {"</title>
130  </head>
131  <body>
132    <h1>Error "} + obj.status + " " + obj.response + {"</h1>
133    <p>"} + obj.response + {"</p>
134    <h3>Guru Meditation:</h3>
135    <p>XID: "} + req.xid + {"</p>
136    <hr>
137    <p>Varnish cache server</p>
138  </body>
139</html>
140"};
141    return (deliver);
142}
Note: See TracBrowser for help on using the browser.