File manager - Edit - /usr/share/doc/varnish/html/users-guide/vcl-built-in-subs.html
Back
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Built-in subroutines — Varnish version 7.1.1 documentation</title> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <link rel="stylesheet" href="../_static/classic.css" type="text/css" /> <script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> <script src="../_static/jquery.js"></script> <script src="../_static/underscore.js"></script> <script src="../_static/doctools.js"></script> <link rel="index" title="Index" href="../genindex.html" /> <link rel="search" title="Search" href="../search.html" /> <link rel="next" title="Built-in VCL" href="vcl-built-in-code.html" /> <link rel="prev" title="VCL Syntax" href="vcl-syntax.html" /> </head><body> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="vcl-built-in-code.html" title="Built-in VCL" accesskey="N">next</a> |</li> <li class="right" > <a href="vcl-syntax.html" title="VCL Syntax" accesskey="P">previous</a> |</li> <li class="nav-item nav-item-0"><a href="../index.html">Varnish version 7.1.1 documentation</a> »</li> <li class="nav-item nav-item-1"><a href="index.html" >The Varnish Users Guide</a> »</li> <li class="nav-item nav-item-2"><a href="vcl.html" accesskey="U">VCL - Varnish Configuration Language</a> »</li> <li class="nav-item nav-item-this"><a href="">Built-in subroutines</a></li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <div class="section" id="built-in-subroutines"> <span id="vcl-built-in-subs"></span><h1>Built-in subroutines<a class="headerlink" href="#built-in-subroutines" title="Permalink to this headline">¶</a></h1> <p>Various built-in subroutines are called during processing of client- and backend requests as well as upon <code class="docutils literal notranslate"><span class="pre">vcl.load</span></code> and <code class="docutils literal notranslate"><span class="pre">vcl.discard</span></code>.</p> <p>See <a class="reference internal" href="../reference/states.html#reference-states"><span class="std std-ref">Varnish Processing States</span></a> for a detailed graphical overview of the states and how they relate to core code functions and VCL subroutines.</p> <p>Built-in subroutines always terminate with a <code class="docutils literal notranslate"><span class="pre">return</span> <span class="pre">(<action>)</span></code>, where <code class="docutils literal notranslate"><span class="pre"><action></span></code> determines how processing continues in the request processing state machine.</p> <p>The behaviour of actions is identical or at least similar across subroutines, so differences are only documented where relevant.</p> <p>Common actions are documented in <a class="reference internal" href="vcl-actions.html#user-guide-vcl-actions"><span class="std std-ref">Actions</span></a>. Actions specific to only one or some subroutines are documented herein.</p> <p>A default behavior is provided for all <a class="reference internal" href="../reference/states.html#reference-states"><span class="std std-ref">Varnish Processing States</span></a> in the <a class="reference internal" href="vcl-built-in-code.html#vcl-built-in-code"><span class="std std-ref">Built-in VCL</span></a> code.</p> <div class="section" id="client-side"> <h2>client side<a class="headerlink" href="#client-side" title="Permalink to this headline">¶</a></h2> <div class="section" id="vcl-recv"> <span id="id1"></span><h3>vcl_recv<a class="headerlink" href="#vcl-recv" title="Permalink to this headline">¶</a></h3> <p>Called at the beginning of a request, after the complete request has been received and parsed, after a <cite>restart</cite> or as the result of an ESI include.</p> <p>Its purpose is to decide whether or not to serve the request, possibly modify it and decide on how to process it further. A backend hint may be set as a default for the backend processing side.</p> <p>The <cite>vcl_recv</cite> subroutine may terminate with calling <code class="docutils literal notranslate"><span class="pre">return()</span></code> on one of the following keywords:</p> <blockquote> <div><dl> <dt><code class="docutils literal notranslate"><span class="pre">fail</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#fail"><span class="std std-ref">fail</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">synth(status</span> <span class="pre">code,</span> <span class="pre">reason)</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#synth"><span class="std std-ref">synth(status code, reason)</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">restart</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#restart"><span class="std std-ref">restart</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">pass</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#pass"><span class="std std-ref">pass</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">pipe</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#pipe"><span class="std std-ref">pipe</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">hash</span></code></dt><dd><p>Continue processing the object as a potential candidate for caching. Passes the control over to <a class="reference internal" href="#vcl-hash"><span class="std std-ref">vcl_hash</span></a>.</p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">purge</span></code></dt><dd><p>Purge the object and it’s variants. Control passes through <a class="reference internal" href="#vcl-hash"><span class="std std-ref">vcl_hash</span></a> to <a class="reference internal" href="#vcl-purge"><span class="std std-ref">vcl_purge</span></a>.</p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">vcl(label)</span></code></dt><dd><p>Switch to vcl labelled <em>label</em>.</p> <p>This will roll back the request as if <code class="docutils literal notranslate"><span class="pre">std.rollback(req)</span></code> was called and continue vcl processing in <a class="reference internal" href="#vcl-recv"><span class="std std-ref">vcl_recv</span></a> of the vcl labelled <em>label</em> as if it was the active vcl.</p> <p>The <code class="docutils literal notranslate"><span class="pre">vcl(label)</span></code> return is only valid while the <code class="docutils literal notranslate"><span class="pre">req.restarts</span></code> count is zero and if used from the active vcl.</p> <p>See the <a class="reference internal" href="../reference/varnish-cli.html#ref-cli-vcl-label"><span class="std std-ref">vcl.label <label> <configname></span></a> command.</p> </dd> </dl> </div></blockquote> </div> <div class="section" id="vcl-pipe"> <span id="id2"></span><h3>vcl_pipe<a class="headerlink" href="#vcl-pipe" title="Permalink to this headline">¶</a></h3> <p>Called upon entering pipe mode. In this mode, the request is passed on to the backend, and any further data from both the client and backend is passed on unaltered until either end closes the connection. Basically, Varnish will degrade into a simple TCP proxy, shuffling bytes back and forth. For a connection in pipe mode, no other VCL subroutine will ever get called after <cite>vcl_pipe</cite>.</p> <p>The <cite>vcl_pipe</cite> subroutine may terminate with calling <code class="docutils literal notranslate"><span class="pre">return()</span></code> with one of the following keywords:</p> <blockquote> <div><dl class="simple"> <dt><code class="docutils literal notranslate"><span class="pre">fail</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#fail"><span class="std std-ref">fail</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">synth(status</span> <span class="pre">code,</span> <span class="pre">reason)</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#synth"><span class="std std-ref">synth(status code, reason)</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">pipe</span></code></dt><dd><p>Proceed with pipe mode.</p> </dd> </dl> </div></blockquote> </div> <div class="section" id="vcl-pass"> <span id="id3"></span><h3>vcl_pass<a class="headerlink" href="#vcl-pass" title="Permalink to this headline">¶</a></h3> <p>Called upon entering pass mode. In this mode, the request is passed on to the backend, and the backend’s response is passed on to the client, but is not entered into the cache. Subsequent requests submitted over the same client connection are handled normally.</p> <p>The <cite>vcl_pass</cite> subroutine may terminate with calling <code class="docutils literal notranslate"><span class="pre">return()</span></code> with one of the following keywords:</p> <blockquote> <div><dl class="simple"> <dt><code class="docutils literal notranslate"><span class="pre">fail</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#fail"><span class="std std-ref">fail</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">synth(status</span> <span class="pre">code,</span> <span class="pre">reason)</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#synth"><span class="std std-ref">synth(status code, reason)</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">restart</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#restart"><span class="std std-ref">restart</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">fetch</span></code></dt><dd><p>Proceed with pass mode - initiate a backend request.</p> </dd> </dl> </div></blockquote> </div> <div class="section" id="vcl-hash"> <span id="id4"></span><h3>vcl_hash<a class="headerlink" href="#vcl-hash" title="Permalink to this headline">¶</a></h3> <p>Called after <cite>vcl_recv</cite> to create a hash value for the request. This is used as a key to look up the object in Varnish.</p> <p>The <cite>vcl_hash</cite> subroutine may terminate with calling <code class="docutils literal notranslate"><span class="pre">return()</span></code> with one of the following keywords:</p> <blockquote> <div><dl> <dt><code class="docutils literal notranslate"><span class="pre">fail</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#fail"><span class="std std-ref">fail</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">lookup</span></code></dt><dd><p>Look up the object in cache.</p> <p>Control passes to <a class="reference internal" href="#vcl-purge"><span class="std std-ref">vcl_purge</span></a> when coming from a <code class="docutils literal notranslate"><span class="pre">purge</span></code> return in <cite>vcl_recv</cite>.</p> <p>Otherwise control passes to the next subroutine depending on the result of the cache lookup:</p> <ul class="simple"> <li><p>a hit: pass to <a class="reference internal" href="#vcl-hit"><span class="std std-ref">vcl_hit</span></a></p></li> <li><p>a miss or a hit on a hit-for-miss object (an object with <code class="docutils literal notranslate"><span class="pre">obj.uncacheable</span> <span class="pre">==</span> <span class="pre">true</span></code>): pass to <a class="reference internal" href="#vcl-miss"><span class="std std-ref">vcl_miss</span></a></p></li> <li><p>a hit on a hit-for-pass object (for which <code class="docutils literal notranslate"><span class="pre">pass(DURATION)</span></code> had been previously returned from <code class="docutils literal notranslate"><span class="pre">vcl_backend_response</span></code>): pass to <a class="reference internal" href="#vcl-pass"><span class="std std-ref">vcl_pass</span></a></p></li> </ul> </dd> </dl> </div></blockquote> </div> <div class="section" id="vcl-purge"> <span id="id5"></span><h3>vcl_purge<a class="headerlink" href="#vcl-purge" title="Permalink to this headline">¶</a></h3> <p>Called after the purge has been executed and all its variants have been evicted.</p> <p>The <cite>vcl_purge</cite> subroutine may terminate with calling <code class="docutils literal notranslate"><span class="pre">return()</span></code> with one of the following keywords:</p> <blockquote> <div><dl class="simple"> <dt><code class="docutils literal notranslate"><span class="pre">fail</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#fail"><span class="std std-ref">fail</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">synth(status</span> <span class="pre">code,</span> <span class="pre">reason)</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#synth"><span class="std std-ref">synth(status code, reason)</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">restart</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#restart"><span class="std std-ref">restart</span></a></p> </dd> </dl> </div></blockquote> </div> <div class="section" id="vcl-miss"> <span id="id6"></span><h3>vcl_miss<a class="headerlink" href="#vcl-miss" title="Permalink to this headline">¶</a></h3> <p>Called after a cache lookup if the requested document was not found in the cache or if <a class="reference internal" href="#vcl-hit"><span class="std std-ref">vcl_hit</span></a> returned <code class="docutils literal notranslate"><span class="pre">fetch</span></code>.</p> <p>Its purpose is to decide whether or not to attempt to retrieve the document from the backend. A backend hint may be set as a default for the backend processing side.</p> <p>The <cite>vcl_miss</cite> subroutine may terminate with calling <code class="docutils literal notranslate"><span class="pre">return()</span></code> with one of the following keywords:</p> <blockquote> <div><dl class="simple"> <dt><code class="docutils literal notranslate"><span class="pre">fail</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#fail"><span class="std std-ref">fail</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">synth(status</span> <span class="pre">code,</span> <span class="pre">reason)</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#synth"><span class="std std-ref">synth(status code, reason)</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">restart</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#restart"><span class="std std-ref">restart</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">pass</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#pass"><span class="std std-ref">pass</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">fetch</span></code></dt><dd><p>Retrieve the requested object from the backend. Control will eventually pass to <cite>vcl_backend_fetch</cite>.</p> </dd> </dl> </div></blockquote> </div> <div class="section" id="vcl-hit"> <span id="id7"></span><h3>vcl_hit<a class="headerlink" href="#vcl-hit" title="Permalink to this headline">¶</a></h3> <p>Called when a cache lookup is successful. The object being hit may be stale: It can have a zero or negative <cite>ttl</cite> with only <cite>grace</cite> or <cite>keep</cite> time left.</p> <p>The <cite>vcl_hit</cite> subroutine may terminate with calling <code class="docutils literal notranslate"><span class="pre">return()</span></code> with one of the following keywords:</p> <blockquote> <div><dl class="simple"> <dt><code class="docutils literal notranslate"><span class="pre">fail</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#fail"><span class="std std-ref">fail</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">synth(status</span> <span class="pre">code,</span> <span class="pre">reason)</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#synth"><span class="std std-ref">synth(status code, reason)</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">restart</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#restart"><span class="std std-ref">restart</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">pass</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#pass"><span class="std std-ref">pass</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">deliver</span></code></dt><dd><p>Deliver the object. If it is stale, a background fetch to refresh it is triggered.</p> </dd> </dl> </div></blockquote> </div> <div class="section" id="vcl-deliver"> <span id="id8"></span><h3>vcl_deliver<a class="headerlink" href="#vcl-deliver" title="Permalink to this headline">¶</a></h3> <p>Called before any object except a <cite>vcl_synth</cite> result is delivered to the client.</p> <p>The <cite>vcl_deliver</cite> subroutine may terminate with calling <code class="docutils literal notranslate"><span class="pre">return()</span></code> with one of the following keywords:</p> <blockquote> <div><dl class="simple"> <dt><code class="docutils literal notranslate"><span class="pre">fail</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#fail"><span class="std std-ref">fail</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">synth(status</span> <span class="pre">code,</span> <span class="pre">reason)</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#synth"><span class="std std-ref">synth(status code, reason)</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">restart</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#restart"><span class="std std-ref">restart</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">deliver</span></code></dt><dd><p>Deliver the object to the client.</p> </dd> </dl> </div></blockquote> </div> <div class="section" id="vcl-synth"> <span id="id9"></span><h3>vcl_synth<a class="headerlink" href="#vcl-synth" title="Permalink to this headline">¶</a></h3> <p>Called to deliver a synthetic object. A synthetic object is generated in VCL, not fetched from the backend. Its body may be constructed using the <code class="docutils literal notranslate"><span class="pre">synthetic()</span></code> function.</p> <p>A <cite>vcl_synth</cite> defined object never enters the cache, contrary to a <a class="reference internal" href="#vcl-backend-error"><span class="std std-ref">vcl_backend_error</span></a> defined object, which may end up in cache.</p> <p>The subroutine may terminate with calling <code class="docutils literal notranslate"><span class="pre">return()</span></code> with one of the following keywords:</p> <blockquote> <div><dl class="simple"> <dt><code class="docutils literal notranslate"><span class="pre">fail</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#fail"><span class="std std-ref">fail</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">restart</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#restart"><span class="std std-ref">restart</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">deliver</span></code></dt><dd><p>Directly deliver the object defined by <cite>vcl_synth</cite> to the client without calling <cite>vcl_deliver</cite>.</p> </dd> </dl> </div></blockquote> </div> </div> <div class="section" id="backend-side"> <h2>Backend Side<a class="headerlink" href="#backend-side" title="Permalink to this headline">¶</a></h2> <div class="section" id="vcl-backend-fetch"> <span id="id10"></span><h3>vcl_backend_fetch<a class="headerlink" href="#vcl-backend-fetch" title="Permalink to this headline">¶</a></h3> <p>Called before sending the backend request. In this subroutine you typically alter the request before it gets to the backend.</p> <p>The <cite>vcl_backend_fetch</cite> subroutine may terminate with calling <code class="docutils literal notranslate"><span class="pre">return()</span></code> with one of the following keywords:</p> <blockquote> <div><dl class="simple"> <dt><code class="docutils literal notranslate"><span class="pre">fail</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#fail"><span class="std std-ref">fail</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">abandon</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#abandon"><span class="std std-ref">abandon</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">fetch</span></code></dt><dd><p>Fetch the object from the backend.</p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">error(status</span> <span class="pre">code,</span> <span class="pre">reason)</span></code></dt><dd><p>Transition to <a class="reference internal" href="#vcl-backend-error"><span class="std std-ref">vcl_backend_error</span></a> with <code class="docutils literal notranslate"><span class="pre">beresp.status</span></code> and <code class="docutils literal notranslate"><span class="pre">beresp.reason</span></code> being preset to the arguments of <code class="docutils literal notranslate"><span class="pre">error()</span></code> if arguments are provided.</p> </dd> </dl> </div></blockquote> <p>Before calling <cite>vcl_backend_fetch</cite>, Varnish core prepares the <cite>bereq</cite> backend request as follows:</p> <ul class="simple"> <li><p>Unless the request is a <cite>pass</cite>,</p> <ul> <li><p>set <code class="docutils literal notranslate"><span class="pre">bereq.method</span></code> to <code class="docutils literal notranslate"><span class="pre">GET</span></code> and <code class="docutils literal notranslate"><span class="pre">bereq.proto</span></code> to <code class="docutils literal notranslate"><span class="pre">HTTP/1.1</span></code> and</p></li> <li><p>set <code class="docutils literal notranslate"><span class="pre">bereq.http.Accept_Encoding</span></code> to <code class="docutils literal notranslate"><span class="pre">gzip</span></code> if <a class="reference internal" href="../reference/varnishd.html#ref-param-http-gzip-support"><span class="std std-ref">http_gzip_support</span></a> is enabled.</p></li> </ul> </li> <li><p>If there is an existing cache object to be revalidated, set <code class="docutils literal notranslate"><span class="pre">bereq.http.If-Modified-Since</span></code> from its <code class="docutils literal notranslate"><span class="pre">Last-Modified</span></code> header and/or set <code class="docutils literal notranslate"><span class="pre">bereq.http.If-None-Match</span></code> from its <code class="docutils literal notranslate"><span class="pre">Etag</span></code> header</p></li> <li><p>Set <code class="docutils literal notranslate"><span class="pre">bereq.http.X-Varnish</span></code> to the current transaction id (<cite>vxid</cite>)</p></li> </ul> <p>These changes can be undone or modified in <cite>vcl_backend_fetch</cite> before the backend request is issued.</p> <p>In particular, to cache non-GET requests, <code class="docutils literal notranslate"><span class="pre">req.method</span></code> needs to be saved to a header or variable in <a class="reference internal" href="#vcl-recv"><span class="std std-ref">vcl_recv</span></a> and restored to <code class="docutils literal notranslate"><span class="pre">bereq.method</span></code>. Notice that caching non-GET requests typically also requires changing the cache key in <a class="reference internal" href="#vcl-hash"><span class="std std-ref">vcl_hash</span></a> e.g. by also hashing the request method and/or request body.</p> <p>HEAD request can be satisfied from cached GET responses.</p> </div> <div class="section" id="vcl-backend-response"> <span id="id11"></span><h3>vcl_backend_response<a class="headerlink" href="#vcl-backend-response" title="Permalink to this headline">¶</a></h3> <p>Called after the response headers have been successfully retrieved from the backend.</p> <p>The <cite>vcl_backend_response</cite> subroutine may terminate with calling <code class="docutils literal notranslate"><span class="pre">return()</span></code> with one of the following keywords:</p> <blockquote> <div><dl class="simple"> <dt><code class="docutils literal notranslate"><span class="pre">fail</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#fail"><span class="std std-ref">fail</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">abandon</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#abandon"><span class="std std-ref">abandon</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">deliver</span></code></dt><dd><p>For a 304 response, create an updated cache object. Otherwise, fetch the object body from the backend and initiate delivery to any waiting client requests, possibly in parallel (streaming).</p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">retry</span></code></dt><dd><p>Retry the backend transaction. Increases the <cite>retries</cite> counter. If the number of retries is higher than <em>max_retries</em>, control will be passed to <a class="reference internal" href="#vcl-backend-error"><span class="std std-ref">vcl_backend_error</span></a>.</p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">pass(duration)</span></code></dt><dd><p>Mark the object as a hit-for-pass for the given duration. Subsequent lookups hitting this object will be turned into passed transactions, as if <code class="docutils literal notranslate"><span class="pre">vcl_recv</span></code> had returned <code class="docutils literal notranslate"><span class="pre">pass</span></code>.</p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">error(status</span> <span class="pre">code,</span> <span class="pre">reason)</span></code></dt><dd><p>Transition to <a class="reference internal" href="#vcl-backend-error"><span class="std std-ref">vcl_backend_error</span></a> with <code class="docutils literal notranslate"><span class="pre">beresp.status</span></code> and <code class="docutils literal notranslate"><span class="pre">beresp.reason</span></code> being preset to the arguments of <code class="docutils literal notranslate"><span class="pre">error()</span></code> if arguments are provided.</p> </dd> </dl> </div></blockquote> </div> <div class="section" id="handling"> <h3>304 handling<a class="headerlink" href="#handling" title="Permalink to this headline">¶</a></h3> <p>For a 304 response, Varnish core code amends <code class="docutils literal notranslate"><span class="pre">beresp</span></code> before calling <cite>vcl_backend_response</cite>:</p> <ul class="simple"> <li><p>If the gzip status changed, <code class="docutils literal notranslate"><span class="pre">Content-Encoding</span></code> is unset and any <code class="docutils literal notranslate"><span class="pre">Etag</span></code> is weakened</p></li> <li><p>Any headers not present in the 304 response are copied from the existing cache object. <code class="docutils literal notranslate"><span class="pre">Content-Length</span></code> is copied if present in the existing cache object and discarded otherwise.</p></li> <li><p>The status gets set to 200.</p></li> </ul> <p><cite>beresp.was_304</cite> marks that this conditional response processing has happened.</p> <p>Note: Backend conditional requests are independent of client conditional requests, so clients may receive 304 responses no matter if a backend request was conditional.</p> </div> <div class="section" id="beresp-ttl-beresp-grace-beresp-keep"> <h3>beresp.ttl / beresp.grace / beresp.keep<a class="headerlink" href="#beresp-ttl-beresp-grace-beresp-keep" title="Permalink to this headline">¶</a></h3> <p>Before calling <cite>vcl_backend_response</cite>, core code sets <code class="docutils literal notranslate"><span class="pre">beresp.ttl</span></code> based on the response status and the response headers <code class="docutils literal notranslate"><span class="pre">Age</span></code>, <code class="docutils literal notranslate"><span class="pre">Cache-Control</span></code> or <code class="docutils literal notranslate"><span class="pre">Expires</span></code> and <code class="docutils literal notranslate"><span class="pre">Date</span></code> as follows:</p> <ul class="simple"> <li><p>If present and valid, the value of the <code class="docutils literal notranslate"><span class="pre">Age</span></code> header is effectively deduced from all ttl calculations.</p></li> <li><p>For status codes 200, 203, 204, 300, 301, 304, 404, 410 and 414:</p> <ul> <li><p>If <code class="docutils literal notranslate"><span class="pre">Cache-Control</span></code> contains an <code class="docutils literal notranslate"><span class="pre">s-maxage</span></code> or <code class="docutils literal notranslate"><span class="pre">max-age</span></code> field (in that order of preference), the ttl is set to the respective non-negative value or 0 if negative.</p></li> <li><p>Otherwise, if no <code class="docutils literal notranslate"><span class="pre">Expires</span></code> header exists, the default ttl is used.</p></li> <li><p>Otherwise, if <code class="docutils literal notranslate"><span class="pre">Expires</span></code> contains a time stamp before <code class="docutils literal notranslate"><span class="pre">Date</span></code>, the ttl is set to 0.</p></li> <li><p>Otherwise, if no <code class="docutils literal notranslate"><span class="pre">Date</span></code> header is present or the <code class="docutils literal notranslate"><span class="pre">Date</span></code> header timestamp differs from the local clock by no more than the <cite>clock_skew</cite> parameter, the ttl is set to</p> <ul> <li><p>0 if <code class="docutils literal notranslate"><span class="pre">Expires</span></code> denotes a past timestamp or</p></li> <li><p>the difference between the local clock and the <code class="docutils literal notranslate"><span class="pre">Expires</span></code> header otherwise.</p></li> </ul> </li> <li><p>Otherwise, the ttl is set to the difference between <code class="docutils literal notranslate"><span class="pre">Expires</span></code> and <code class="docutils literal notranslate"><span class="pre">Date</span></code></p></li> </ul> </li> <li><p>For status codes 302 and 307, the calculation is identical except that the default ttl is not used and -1 is returned if neither <code class="docutils literal notranslate"><span class="pre">Cache-Control</span></code> nor <code class="docutils literal notranslate"><span class="pre">Expires</span></code> exists.</p></li> <li><p>For all other status codes, ttl -1 is returned.</p></li> </ul> <p><code class="docutils literal notranslate"><span class="pre">beresp.grace</span></code> defaults to the <cite>default_grace</cite> parameter.</p> <p>For a non-negative ttl, if <code class="docutils literal notranslate"><span class="pre">Cache-Control</span></code> contains a <code class="docutils literal notranslate"><span class="pre">stale-while-revalidate</span></code> field value, <code class="docutils literal notranslate"><span class="pre">beresp.grace</span></code> is set to that value if non-negative or 0 otherwise.</p> <p><code class="docutils literal notranslate"><span class="pre">beresp.keep</span></code> defaults to the <cite>default_keep</cite> parameter.</p> </div> <div class="section" id="vcl-backend-error"> <span id="id12"></span><h3>vcl_backend_error<a class="headerlink" href="#vcl-backend-error" title="Permalink to this headline">¶</a></h3> <p>This subroutine is called if we fail the backend fetch or if <em>max_retries</em> has been exceeded.</p> <p>Returning with <a class="reference internal" href="vcl-actions.html#abandon"><span class="std std-ref">abandon</span></a> does not leave a cache object.</p> <p>If returning with <code class="docutils literal notranslate"><span class="pre">deliver</span></code> and a <code class="docutils literal notranslate"><span class="pre">beresp.ttl</span> <span class="pre">></span> <span class="pre">0s</span></code>, a synthetic cache object is generated in VCL, whose body may be constructed using the <code class="docutils literal notranslate"><span class="pre">synthetic()</span></code> function.</p> <p>When there is a waiting list on the object, the default <code class="docutils literal notranslate"><span class="pre">ttl</span></code> will be positive (currently one second), set before entering <code class="docutils literal notranslate"><span class="pre">vcl_backend_error</span></code>. This is to avoid request serialization and hammering on a potentially failing backend.</p> <p>Since these synthetic objects are cached in these special circumstances, be cautious with putting private information there. If you really must, then you need to explicitly set <code class="docutils literal notranslate"><span class="pre">beresp.ttl</span></code> to zero in <code class="docutils literal notranslate"><span class="pre">vcl_backend_error</span></code>.</p> <p>The <cite>vcl_backend_error</cite> subroutine may terminate with calling <code class="docutils literal notranslate"><span class="pre">return()</span></code> with one of the following keywords:</p> <blockquote> <div><dl class="simple"> <dt><code class="docutils literal notranslate"><span class="pre">fail</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#fail"><span class="std std-ref">fail</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">abandon</span></code></dt><dd><p>see <a class="reference internal" href="vcl-actions.html#abandon"><span class="std std-ref">abandon</span></a></p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">deliver</span></code></dt><dd><p>Deliver and possibly cache the object defined in <cite>vcl_backend_error</cite> <strong>as if it was fetched from the backend</strong>, also referred to as a “backend synth”.</p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">retry</span></code></dt><dd><p>Retry the backend transaction. Increases the <cite>retries</cite> counter. If the number of retries is higher than <em>max_retries</em>, <a class="reference internal" href="#vcl-synth"><span class="std std-ref">vcl_synth</span></a> on the client side is called with <code class="docutils literal notranslate"><span class="pre">resp.status</span></code> preset to 503.</p> </dd> </dl> </div></blockquote> </div> </div> <div class="section" id="during-vcl-load-vcl-discard"> <h2>During vcl.load / vcl.discard<a class="headerlink" href="#during-vcl-load-vcl-discard" title="Permalink to this headline">¶</a></h2> <div class="section" id="vcl-init"> <span id="id13"></span><h3>vcl_init<a class="headerlink" href="#vcl-init" title="Permalink to this headline">¶</a></h3> <p>Called when VCL is loaded, before any requests pass through it. Typically used to initialize VMODs.</p> <p>The <cite>vcl_init</cite> subroutine may terminate with calling <code class="docutils literal notranslate"><span class="pre">return()</span></code> with one of the following keywords:</p> <blockquote> <div><dl class="simple"> <dt><code class="docutils literal notranslate"><span class="pre">ok</span></code></dt><dd><p>Normal return, VCL continues loading.</p> </dd> <dt><code class="docutils literal notranslate"><span class="pre">fail</span></code></dt><dd><p>Abort loading of this VCL.</p> </dd> </dl> </div></blockquote> </div> <div class="section" id="vcl-fini"> <span id="id14"></span><h3>vcl_fini<a class="headerlink" href="#vcl-fini" title="Permalink to this headline">¶</a></h3> <p>Called when VCL is discarded only after all requests have exited the VCL. Typically used to clean up VMODs.</p> <p>The <cite>vcl_fini</cite> subroutine may terminate with calling <code class="docutils literal notranslate"><span class="pre">return()</span></code> with one of the following keywords:</p> <blockquote> <div><dl class="simple"> <dt><code class="docutils literal notranslate"><span class="pre">ok</span></code></dt><dd><p>Normal return, VCL will be discarded.</p> </dd> </dl> </div></blockquote> </div> </div> </div> <div class="clearer"></div> </div> </div> </div> <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> <div class="sphinxsidebarwrapper"> <h3><a href="../index.html">Table of Contents</a></h3> <ul> <li><a class="reference internal" href="#">Built-in subroutines</a><ul> <li><a class="reference internal" href="#client-side">client side</a><ul> <li><a class="reference internal" href="#vcl-recv">vcl_recv</a></li> <li><a class="reference internal" href="#vcl-pipe">vcl_pipe</a></li> <li><a class="reference internal" href="#vcl-pass">vcl_pass</a></li> <li><a class="reference internal" href="#vcl-hash">vcl_hash</a></li> <li><a class="reference internal" href="#vcl-purge">vcl_purge</a></li> <li><a class="reference internal" href="#vcl-miss">vcl_miss</a></li> <li><a class="reference internal" href="#vcl-hit">vcl_hit</a></li> <li><a class="reference internal" href="#vcl-deliver">vcl_deliver</a></li> <li><a class="reference internal" href="#vcl-synth">vcl_synth</a></li> </ul> </li> <li><a class="reference internal" href="#backend-side">Backend Side</a><ul> <li><a class="reference internal" href="#vcl-backend-fetch">vcl_backend_fetch</a></li> <li><a class="reference internal" href="#vcl-backend-response">vcl_backend_response</a></li> <li><a class="reference internal" href="#handling">304 handling</a></li> <li><a class="reference internal" href="#beresp-ttl-beresp-grace-beresp-keep">beresp.ttl / beresp.grace / beresp.keep</a></li> <li><a class="reference internal" href="#vcl-backend-error">vcl_backend_error</a></li> </ul> </li> <li><a class="reference internal" href="#during-vcl-load-vcl-discard">During vcl.load / vcl.discard</a><ul> <li><a class="reference internal" href="#vcl-init">vcl_init</a></li> <li><a class="reference internal" href="#vcl-fini">vcl_fini</a></li> </ul> </li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="vcl-syntax.html" title="previous chapter">VCL Syntax</a></p> <h4>Next topic</h4> <p class="topless"><a href="vcl-built-in-code.html" title="next chapter">Built-in VCL</a></p> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../_sources/users-guide/vcl-built-in-subs.rst.txt" rel="nofollow">Show Source</a></li> </ul> </div> <div id="searchbox" style="display: none" role="search"> <h3 id="searchlabel">Quick search</h3> <div class="searchformwrapper"> <form class="search" action="../search.html" method="get"> <input type="text" name="q" aria-labelledby="searchlabel" /> <input type="submit" value="Go" /> </form> </div> </div> <script>$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="vcl-built-in-code.html" title="Built-in VCL" >next</a> |</li> <li class="right" > <a href="vcl-syntax.html" title="VCL Syntax" >previous</a> |</li> <li class="nav-item nav-item-0"><a href="../index.html">Varnish version 7.1.1 documentation</a> »</li> <li class="nav-item nav-item-1"><a href="index.html" >The Varnish Users Guide</a> »</li> <li class="nav-item nav-item-2"><a href="vcl.html" >VCL - Varnish Configuration Language</a> »</li> <li class="nav-item nav-item-this"><a href="">Built-in subroutines</a></li> </ul> </div> <div class="footer" role="contentinfo"> © Copyright 2010-2014, Varnish Software AS. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.4.3. </div> </body> </html>
| ver. 1.4 |
Github
|
.
| PHP 8.2.9 | Generation time: 0.08 |
proxy
|
phpinfo
|
Settings