.\" Man page generated from reStructuredText. . .TH VMOD_HEADER 3 "" "" "" .SH NAME vmod_header \- Header VMOD for Varnish . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .\" . .\" NB: This file is machine generated, DO NOT EDIT! . .\" . .\" Edit ./vmod_header.vcc and run make instead . .\" . .SH SYNOPSIS .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C import header [as name] [from "path"] VOID append(HEADER, STRING) VOID copy(HEADER, HEADER) STRING get(HEADER header, STRING regex) VOID remove(HEADER header, STRING regex) VOID regsub(HTTP, STRING regex, STRING sub, BOOL all) .ft P .fi .UNINDENT .UNINDENT .SH DESCRIPTION .sp Varnish Module for manipulation of duplicated HTTP headers, for instance multiple Set\-Cookie headers. .\" vcl-start . .sp Example: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C 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\(aqt really need it. header.remove(beresp.http.Set\-Cookie, "JSESSIONID="); } } .ft P .fi .UNINDENT .UNINDENT .\" vcl-end . .SS VOID append(HEADER, STRING) .INDENT 0.0 .TP .B Description Append an extra occurrence to an existing header. .TP .B Example :: header.append(beresp.http.Set\-Cookie, "foo=bar") .UNINDENT .SS VOID copy(HEADER, HEADER) .INDENT 0.0 .TP .B Description Copy all source headers to a new header. .TP .B Example :: header.copy(beresp.http.set\-cookie, beresp.http.x\-old\-cookie); .UNINDENT .SS STRING get(HEADER header, STRING regex) .INDENT 0.0 .TP .B Description Fetches the value of the first \fIheader\fP that matches the given regular expression \fIregex\fP\&. .TP .B Example :: set beresp.http.xusr = header.get(beresp.http.set\-cookie,"user="); .UNINDENT .SS VOID remove(HEADER header, STRING regex) .INDENT 0.0 .TP .B Description Remove all occurrences of \fIheader\fP that matches \fIregex\fP\&. .TP .B Example :: header.remove(beresp.http.set\-cookie,"^(?!(funcookie=))"); .UNINDENT .SS VOID regsub(HTTP, STRING regex, STRING sub, BOOL all=0) .INDENT 0.0 .TP .B Description For every header line in the HTTP object, which can be one of \fBreq\fP, \fBresp\fP, \fBbereq\fP or \fBberesp\fP, if the line matches the regular expression \fBregex\fP, then replace it with the result of a substitution using the string \fBsub\fP\&. \fBsub\fP may include backreferences of the form \fB\e1\fP through \fB\e9\fP, which refer to capturing expressions in the \fBregex\fP, or \fB\e0\fP to refer to the entire matched portion of the header line. .sp If \fBall\fP is \fBfalse\fP, replace the first matched portion of the header line with \fBsub\fP\&. This is the same operation performed by the VCL native function \fBregsub()\fP\&. \fBall\fP is \fBfalse\fP by default. .sp If \fBall\fP is \fBtrue\fP, replace each non\-overlapping matched portion of the header line with \fBsub\fP\&. This is the same operation performed by native \fBregsuball()\fP\&. .sp Note that unlike the other functions in this VMOD, \fBregsub()\fP applies to the \fIentire\fP header line, including the header name, colon separator, and header value. Take care that your substitutions result in valid headers, since ill\-formed headers can interfere with the HTTP protocol. .sp Consider case sensitivity in the regex match. The standard dictates that header names are case insensitive, but header values are not. The VMOD function does not take care of that for you, but you can express it in the \fBregex\fP using the \fB(?i)\fP flag, as shown in the example below (use \fB(?\-i)\fP to turn it off). .sp Consider using the \fB^\fP starting anchor in \fBregex\fP to be sure to match a header name (and not the same string somewhere in the middle of the line). .TP .B Example :: header.regsub(req, "^(?i)Foo(\ed): (?\-i)bar=(.*)$", "Bar\e1: \e2") .UNINDENT .SH ACKNOWLEDGEMENTS .sp The development of this plugin was made possible by the sponsorship of Softonic, \fI\%http://en.softonic.com/\fP . .sp Also thanks to Imo Klabun and Anders Nordby for bug reports. .SH BUGS .sp You can\(aqt use dynamic regular expressions, which also holds true for normal regular expressions in regsub(). .\" Generated by docutils manpage writer. .