Search
Varnish Enterprise

Introduction Installation Upgrading Troubleshooting Changelog Changelog for 6.0.x Changes (Varnish Cache 4.1) Changes (Varnish Cache Plus 4.1) Known Issues Features Backend SSL/TLS Client SSL/TLS termination Cluster In-Process TLS MSE 4 Basic Configuration / Getting Started Configuration Persisted caching Categories Configuration Reference MSE 3.0 Settings mkfs.mse Memory Governor MSE 2.0 NUMA Parallel ESI Backend health counter HTTP/2 Support JSON Logging TCP Only Probes Timeouts Transit Buffer Varnish scoreboard VMODs Accept Accounting ACL (aclplus) ActiveDNS Akamai Connector AWS VCL Body Access & Transformation (xbody) Brotli Cookie Plus (cookieplus) DeviceAtlas DeviceAtlas3 Digest Dynamic backends (goto) Edgestash File Format Geolocation (geoip/mmdb) Header Manipulation (headerplus) HTTP communication (http) Image JSON parsing (json) JWT Key value storage (kvstore) Least connections director (leastconn) Module to control the built-in HTTP2 transport (h2) MSE control (mse) MSE4 control (mse4) Probe Proxy ProxyV2 TLV Attribute Extraction (proxy) Pseudo Random Number Generator Purge (purge/softpurge) Real-time Status (rtstatus) Reverse DNS (resolver) Rewrite S3 VMOD Session Slicer SQLite3 Stale Standard (std) Stat (Prometheus) Strings (str) Synthetic backends (synthbackend) Tag-based invalidation (Ykey/Xkey) TCP configuration (tcp) TLS Total Encryption (crypto) Unified director object (udo) Uniform Resource Identifier (uri) Unix Socket Utilities (unix) URL Plus (urlplus) Utils Vsthrottle

Header manipulation (header)

Description

Varnish Module for manipulation of duplicated HTTP headers, for instance multiple Set-Cookie headers. Note that for Cookie and Set-Cookie we recommend using the cookieplus VMOD, while this VMOD should be used for other headers that may occur more than once in a HTTP response.

Example VCL

vcl 4.0;

import header;

backend default { .host = "192.0.2.11"; .port = "8080"; }

sub vcl_backend_response {
    if (beresp.http.Set-Cookie) {
        # Add another line of Set-Cookie in the response.
        header.append(beresp.http.Set-Cookie, "VSESS=abbabeef");

        # CMS always set this, but doesn't really need it.
        header.remove(beresp.http.Set-Cookie, "JSESSIONID=");
    }
}

Functions

The following functions are available:

append

VOID append(HEADER, STRING)

  • Description:

    Create a new header field with the given string as value, allowing duplicates. This is used for example to have multiple cookie header fields.

  • Example:

    header.append(beresp.http.Set-Cookie, "foo=bar");

copy

VOID copy(HEADER sources, HEADER merged)

  • Description:

    Copy all source headers to one new header, merging all the values.

  • Example:

    header.copy(beresp.http.set-cookie, beresp.http.x-old-cookie);

get

STRING get(HEADER header, STRING regex)

  • Description:

    Fetches the value of the first header that matches the given regular expression regex. regex is static and cannot change between calls.

  • Example:

    set beresp.http.xusr = header.get(beresp.http.set-cookie,"user=");

remove

VOID remove(HEADER header, STRING regex)

  • Description:

    Remove all occurences of header that matches regex. regex is static and cannot change between calls.

  • Example:

    header.remove(beresp.http.set-cookie,"^(?!(funcookie=))");

ACKNOWLEDGEMENTS

The development of this plugin was made possible by the sponsorship of Softonic, http://en.softonic.com/ .

Also thanks to Imo Klabun and Anders Nordby for bug reports.

BUGS

You can’t use dynamic regular expressions, which also holds true for normal regular expressions in regsub().


®Varnish Software, Wallingatan 12, 111 60 Stockholm, Organization nr. 556805-6203