Commit 8d9df0a0 authored by Julian Wiesener's avatar Julian Wiesener

added doc to vcc, named arguments

parent cc267fcd
Pipeline #21 skipped
......@@ -26,3 +26,6 @@ stamp-h1
compile
vmod_vtstor.3
src/*.rst
*.log
*.trs
test-driver
......@@ -26,7 +26,7 @@ varnish v1 -vcl+backend {
import std;
sub vcl_init {
new inst = vtstor.vtstor(0, 0, 0, 0);
new inst = vtstor.vtstor();
}
sub vcl_recv {
......
......@@ -7,7 +7,7 @@ varnish v1 -vcl+backend {
import std;
sub vcl_init {
new zero = vtstor.vtstor(0, 0, 0, 0);
new zero = vtstor.vtstor();
}
sub vcl_recv {
......
......@@ -7,7 +7,7 @@ varnish v1 -vcl+backend {
import std;
sub vcl_init {
new zero = vtstor.vtstor(0, 0, 0, 0);
new zero = vtstor.vtstor();
}
sub vcl_recv {
......
varnishtest "vtstor-vmod: test the contructor with arguments"
server s1 {} -start
varnish v1 -vcl+backend {
import vtstor from "${vmod_topbuild}/src/.libs/libvmod_vtstor.so";
import std;
sub vcl_init {
new zero = vtstor.vtstor(64, 10, 8, 32);
}
sub vcl_recv {
return(synth(200, "OK"));
}
sub vcl_synth {
set resp.http.Zero-Buckets = zero.buckets();
set resp.http.Zero-Timeout = zero.timeout();
set resp.http.Zero-Keymax = zero.key_max();
set resp.http.Zero-Valmax = zero.value_max();
}
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.http.Zero-Buckets == "64"
expect resp.http.Zero-Timeout == "10"
expect resp.http.Zero-Keymax == "8"
expect resp.http.Zero-Valmax == "32"
} -run
varnishtest "vtstor-vmod: named arguments for store"
server s1 {
rxreq
expect req.url == "/including1"
txresp -status 200 -hdr "Set-Cookie: foo=bar" -body {
<esi:include src="/included1"/>
}
rxreq
expect req.url == "/included1"
expect req.http.Cookie == "foo=bar"
txresp
rxreq
expect req.url == "/including2"
txresp -status 200 -hdr "Set-Cookie: baz=quux" -body {
<esi:include src="/included2"/>
}
rxreq
expect req.url == "/included2"
expect req.http.Cookie == "baz=quux"
txresp
} -start
varnish v1 -vcl+backend {
import vtstor from "${vmod_topbuild}/src/.libs/libvmod_vtstor.so";
import std;
sub vcl_init {
new inst = vtstor.vtstor();
}
sub vcl_recv {
set req.http.X-VXID = vtstor.vxid();
unset req.http.X-Cookie-Inject;
set req.http.X-Cookie-Inject = inst.get(req.http.X-VXID);
if (req.http.X-Cookie-Inject != "" && req.http.Cookie) {
set req.http.Cookie = req.http.Cookie + ";"
+ req.http.X-Cookie-Inject;
}
elsif (req.http.X-Cookie-Inject != "") {
set req.http.Cookie = req.http.X-Cookie-Inject;
}
unset req.http.X-Cookie-Inject;
}
sub vcl_backend_response {
set beresp.do_esi = true;
if (beresp.http.Set-Cookie) {
inst.store(key=bereq.http.X-VXID,
value=regsub(beresp.http.Set-Cookie,
"^.*\b(\w+\s*=\s*\w+).*$", "\1"));
}
}
} -start
client c1 {
txreq -url "/including1"
timeout 2
rxresp
expect resp.status == 200
txreq -url "/including2"
timeout 2
rxresp
expect resp.status == 200
} -run
/*-
* Copyright (c) 2015 UPLEX - Nils Goroll Systemoptimierung
* Copyright (c) 2015-2016 UPLEX - Nils Goroll Systemoptimierung
* All rights reserved.
*
* Author: Julian Wiesener <jw@uplex.de>
......@@ -49,17 +49,10 @@ vmod_vtstor__init(VRT_CTX, struct vmod_vtstor_vtstor **vmip,
vmi->alloc = vtstor_alloc;
vmi->dealloc = vtstor_dealloc;
#define CONFIG(f,d,v) do { \
vmi->f = (d); \
if ((v) > 0) \
vmi->f = (v); \
} while (0)
CONFIG(buckets, DEFAULT_NBUCKETS, nbuckets);
CONFIG(timeout, DEFAULT_TIMEOUT, timeout);
CONFIG(key_max, DEFAULT_KEYMAX, keymax);
CONFIG(value_max, DEFAULT_VALMAX, valmax);
#undef CONFIG
vmi->buckets = nbuckets;
vmi->timeout = timeout;
vmi->key_max = keymax;
vmi->value_max = valmax;
vmi->map = vtstor_init(vmi);
*vmip = vmi;
......
#-
# Copyright (c) 2015 UPLEX - Nils Goroll Systemoptimierung
# Copyright (c) 2015-2016 UPLEX - Nils Goroll Systemoptimierung
# All rights reserved.
#
# Author: Julian Wiesener <jw@uplex.de>
......@@ -28,15 +28,104 @@
$Module vtstor 3 Generic hash-based key/value store VMOD
$Object vtstor(INT, INT, INT, INT)
$Method VOID .store(STRING, HEADER)
DESCRIPTION
===========
Temporary key-value storage for vcl. If not explicit deleted, pairs might get replaced after the configured timeout, if the slot is needed by a new pair. As the storage is available everywhere in vlc, it allows to transport values where it would not be possible otherwise for example cookies from responses to consecutive ESI requests. The storage is a hash table with a list per bucket. There are no global locks thus contention happens only if multiple thread access the same bucket at the same time.
$Object vtstor(
INT nbuckets = 1024,
INT timeout = 60,
INT keymax = 64,
INT valmax = 4096)
Description
Create vtstor instance.
- *nbuckets* (defaults to ``1024``)
- *timeout* in seconds (defaults to ``60``)
- *keymax* maximum key length (defaults to ``64``)
- *valmax* maximum value length (defaults to ``64``)
$Method VOID .store(
STRING value,
HEADER key)
Description
Store key-value pair.
- *value*
- *key*
$Method STRING .get(HEADER)
Description
Return value for key.
$Method VOID .delete(HEADER)
Description
Delete value for key.
$Method INT .buckets()
Description
Return the configured number of buckets.
$Method INT .timeout()
Description
Return the configured timeout.
$Method INT .key_max()
Description
Return the configured maximum key length.
$Method INT .value_max()
Description
Return the configured maximum value length.
$Function STRING vxid()
Description
Return the varnish vxid(Varnish Transaction ID) which can be used as key.
$Function STRING version()
Description
Return the vmod version.
EXAMPLE
=======
::
import vtstor;
sub vcl_init {
new inst = vtstor.vtstor();
}
sub vcl_recv {
set req.http.X-VXID = vtstor.vxid();
if(req.url ~ "^.*esi") {
set req.http.Cookie = inst.get(req.http.X-VXID);
}
}
sub vcl_backend_response {
set beresp.do_esi = true;
if(bereq.url !~ "^.*esi" && beresp.http.Set-Cookie) {
inst.store(beresp.http.Set-Cookie, req.http.X-VXID)
}
}
SEE ALSO
========
``vcl``\(7),
``vsl``\(7)
......@@ -33,11 +33,6 @@
#include "vcc_if.h"
#define DEFAULT_NBUCKETS 1024
#define DEFAULT_TIMEOUT 60
#define DEFAULT_KEYMAX 64
#define DEFAULT_VALMAX 4096
struct vmod_vtstor_vtstor;
typedef size_t (*malloc_func)(struct vmod_vtstor_vtstor *, size_t, char **);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment