.\" Man page generated from reStructuredText. . . .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 .. .TH "VMOD_VAR" 3 "" "" "" .SH NAME vmod_var \- Variable support for Varnish VCL .\" . .\" NB: This file is machine generated, DO NOT EDIT! . .\" . .\" Edit ./vmod_var.vcc and run make instead . .\" . .SH SYNOPSIS .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C import var [as name] [from "path"] VOID set(STRING key, STRING value) STRING get(STRING) VOID global_set(STRING, STRING) STRING global_get(STRING) VOID set_int(STRING key, INT value) INT get_int(STRING key) VOID set_string(STRING key, STRING value) STRING get_string(STRING key) VOID set_real(STRING key, REAL value) REAL get_real(STRING key) VOID set_duration(STRING key, DURATION value) DURATION get_duration(STRING key) VOID set_ip(STRING key, IP value) IP get_ip(STRING key) VOID set_backend(STRING key, BACKEND value) BACKEND get_backend(STRING key) VOID clear() .ft P .fi .UNINDENT .UNINDENT .sp This VMOD implements basic variable support in VCL. .sp It supports strings, integers, real numbers, durations, IP addresses and backends. There are methods to get and set each data type. .sp Global variables have a lifespan that extends across requests and VCLs, for as long as the vmod is loaded. Global variables only support strings. .sp The remaining functions have PRIV_TASK lifespan and are local to a single request or backend request. .\" vcl-start . .sp Example: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C vcl 4.0; import var; backend default { .host = "192.0.2.11"; .port = "8080"; } sub vcl_recv { # Set and get some values. var.set("foo", "bar"); set req.http.x\-foo = var.get("foo"); var.set_int("ten", 10); var.set_int("five", 5); set req.http.twenty = var.get_int("ten") + var.get_int("five") + 5; # VCL will use the first token to decide final data type. Headers are strings. # set req.http.X\-lifetime = var.get_int("ten") + " seconds"; # Won\(aqt work. set req.http.X\-lifetime = "" + var.get_int("ten") + " seconds"; # Works! var.set_duration("timedelta", 1m); # 60s set req.http.d1 = var.get_duration("timedelta"); var.set_ip("endpoint", client.ip); set req.http.x\-client = var.get_ip("endpoint"); # Unset all non\-global variables. var.clear(); # Demonstrate use of global variables as state flags. if (req.url ~ "/close$") { var.global_set("open", "no"); } else if (req.url ~ "/open$") { var.global_set("open", "yes"); } if (var.global_get("open") != "yes") { return (synth(200, "We are currently closed, sorry!")); } } .ft P .fi .UNINDENT .UNINDENT .\" vcl-end . .SS VOID set(STRING key, STRING value) .sp Set \fIkey\fP to \fIvalue\fP\&. .SS STRING get(STRING) .sp Get \fIkey\fP with data type STRING. If stored \fIkey\fP is not a STRING an empty string is returned. .SS VOID global_set(STRING, STRING) .SS STRING global_get(STRING) .SS VOID set_int(STRING key, INT value) .sp Set \fIkey\fP to \fIvalue\fP\&. .SS INT get_int(STRING key) .sp Get \fIkey\fP with data type INT. If stored \fIkey\fP is not an INT zero will be returned. .SS VOID set_string(STRING key, STRING value) .sp Identical to set(). .SS STRING get_string(STRING key) .sp Identical to get(). .SS VOID set_real(STRING key, REAL value) .sp Set \fIkey\fP to \fIvalue\fP\&. .SS REAL get_real(STRING key) .sp Get \fIkey\fP with data type REAL. If stored \fIkey\fP is not a REAL zero will be returned. .SS VOID set_duration(STRING key, DURATION value) .sp Set \fIkey\fP to \fIvalue\fP\&. .SS DURATION get_duration(STRING key) .sp Get \fIkey\fP with data type DURATION. If stored \fIkey\fP is not a DURATION zero will be returned. .SS VOID set_ip(STRING key, IP value) .sp Set \fIkey\fP to \fIvalue\fP\&. .SS IP get_ip(STRING key) .sp Get \fIkey\fP with data type IP. If stored \fIkey\fP is not an IP null will be returned. .SS VOID set_backend(STRING key, BACKEND value) .sp Set \fIkey\fP to \fIvalue\fP\&. .SS BACKEND get_backend(STRING key) .sp Get \fIkey\fP with data type BACKEND. If stored \fIkey\fP is not a BACKEND, null will be returned. .SS VOID clear() .sp Clear all non\-global variables. .\" Generated by docutils manpage writer. .