1VMOD_HEADER(3)                                                  VMOD_HEADER(3)
2
3
4

NAME

6       vmod_header - Header VMOD for Varnish
7

SYNOPSIS

9          import header [as name] [from "path"]
10
11          VOID append(HEADER, STRING)
12
13          VOID copy(HEADER, HEADER)
14
15          STRING get(HEADER header, STRING regex)
16
17          VOID remove(HEADER header, STRING regex)
18
19          VOID regsub(HTTP, STRING regex, STRING sub, BOOL all)
20

DESCRIPTION

22       Varnish  Module  for  manipulation  of  duplicated  HTTP  headers,  for
23       instance multiple Set-Cookie headers.
24
25       Example:
26
27          vcl 4.0;
28          import header;
29
30          backend default { .host = "192.0.2.11"; .port = "8080"; }
31
32          sub vcl_backend_response {
33              if (beresp.http.Set-Cookie) {
34                  # Add another line of Set-Cookie in the response.
35                  header.append(beresp.http.Set-Cookie, "VSESS=abbabeef");
36
37                  # CMS always set this, but doesn't really need it.
38                  header.remove(beresp.http.Set-Cookie, "JSESSIONID=");
39              }
40          }
41
42   VOID append(HEADER, STRING)
43       Description
44              Append an extra occurrence to an existing header.
45
46       Example
47              :: header.append(beresp.http.Set-Cookie, "foo=bar")
48
49   VOID copy(HEADER, HEADER)
50       Description
51              Copy all source headers to a new header.
52
53       Example
54              ::                           header.copy(beresp.http.set-cookie,
55              beresp.http.x-old-cookie);
56
57   STRING get(HEADER header, STRING regex)
58       Description
59              Fetches  the  value  of  the first header that matches the given
60              regular expression regex.
61
62       Example
63              ::              set              beresp.http.xusr              =
64              header.get(beresp.http.set-cookie,"user=");
65
66   VOID remove(HEADER header, STRING regex)
67       Description
68              Remove all occurrences of header that matches regex.
69
70       Example
71              :: header.remove(beresp.http.set-cookie,"^(?!(funcookie=))");
72
73   VOID regsub(HTTP, STRING regex, STRING sub, BOOL all=0)
74       Description
75              For  every  header  line in the HTTP object, which can be one of
76              req, resp, bereq or beresp, if  the  line  matches  the  regular
77              expression regex, then replace it with the result of a substitu‐
78              tion using the string sub. sub may include backreferences of the
79              form  \1 through \9, which refer to capturing expressions in the
80              regex, or \0 to refer to  the  entire  matched  portion  of  the
81              header line.
82
83              If all is false, replace the first matched portion of the header
84              line with sub. This is the same operation performed by  the  VCL
85              native function regsub(). all is false by default.
86
87              If  all is true, replace each non-overlapping matched portion of
88              the header line with sub. This is the same  operation  performed
89              by native regsuball().
90
91              Note  that  unlike  the  other  functions in this VMOD, regsub()
92              applies to the entire header line, including  the  header  name,
93              colon separator, and header value. Take care that your substitu‐
94              tions result in valid  headers,  since  ill-formed  headers  can
95              interfere with the HTTP protocol.
96
97              Consider  case sensitivity in the regex match. The standard dic‐
98              tates that header names are case insensitive, but header  values
99              are  not.  The VMOD function does not take care of that for you,
100              but you can express it in the regex  using  the  (?i)  flag,  as
101              shown in the example below (use (?-i) to turn it off).
102
103              Consider  using  the  ^  starting  anchor in regex to be sure to
104              match a header name (and not the same string  somewhere  in  the
105              middle of the line).
106
107       Example
108              ::  header.regsub(req,  "^(?i)Foo(\d):  (?-i)bar=(.*)$", "Bar\1:
109              \2")
110

ACKNOWLEDGEMENTS

112       The development of this plugin was made possible by the sponsorship  of
113       Softonic, http://en.softonic.com/ .
114
115       Also thanks to Imo Klabun and Anders Nordby for bug reports.
116

BUGS

118       You  can't  use  dynamic regular expressions, which also holds true for
119       normal regular expressions in regsub().
120
121
122
123
124                                                                VMOD_HEADER(3)
Impressum