Commit 8c9b7615 authored by Geoff Simmons's avatar Geoff Simmons

Add the .id() method.

parent fab4fff9
.. ..
.. NB: This file is machine generated, DO NOT EDIT! .. NB: This file is machine generated, DO NOT EDIT!
.. ..
.. Edit vmod.vcc and run make instead .. Edit ./vmod_file.vcc and run make instead
.. ..
.. role:: ref(emphasis) .. role:: ref(emphasis)
========= =========
VMOD file vmod_file
========= =========
----------------------------------------------------------------- -----------------------------------------------------------------
...@@ -452,6 +452,13 @@ Example:: ...@@ -452,6 +452,13 @@ Example::
set resp.http.Cache-Control = "public, max-age=" set resp.http.Cache-Control = "public, max-age="
+ std.integer(duration=rdr.next_check()); + std.integer(duration=rdr.next_check());
.. _xreader.id():
BLOB xreader.id()
-----------------
XXX ...
.. _file.version(): .. _file.version():
STRING version() STRING version()
......
...@@ -178,3 +178,37 @@ client c1 { ...@@ -178,3 +178,37 @@ client c1 {
expect resp.http.Error == "false" expect resp.http.Error == "false"
expect resp.http.Deleted == "true" expect resp.http.Deleted == "true"
} -run } -run
shell {touch ${tmpdir}/id}
varnish v1 -vcl {
import ${vmod_file};
import blob;
backend b None;
sub vcl_init {
new rdr = file.reader("${tmpdir}/id", ttl=0.1s);
}
sub vcl_recv {
return (synth(200));
}
sub vcl_synth {
set resp.http.ETag = blob.encode(BASE64, blob=rdr.id());
return (deliver);
}
}
client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.http.ETag ~ {^[[:alnum:]+/]+=*$}
} -run
shell {touch ${tmpdir}/id}
delay .1
# Check the log to verify that ETag changes.
client c1 -run
...@@ -58,6 +58,9 @@ ...@@ -58,6 +58,9 @@
/* Other VMODs may check the result of .blob() for this value, see vrt.h */ /* Other VMODs may check the result of .blob() for this value, see vrt.h */
#define VMOD_FILE_BLOB_MAGIC 0x069392c4 #define VMOD_FILE_BLOB_MAGIC 0x069392c4
/* For the result of .id() */
#define VMOD_FILE_ID_MAGIC 0x001122d7
#define INIT_SLEEP_INTERVAL 0.001 #define INIT_SLEEP_INTERVAL 0.001
#define ERRMSG_LEN 128 #define ERRMSG_LEN 128
#define NO_ERR ("No error") #define NO_ERR ("No error")
...@@ -663,6 +666,59 @@ vmod_reader_next_check(VRT_CTX, struct VPFX(file_reader) *rdr) ...@@ -663,6 +666,59 @@ vmod_reader_next_check(VRT_CTX, struct VPFX(file_reader) *rdr)
return (t.it_value.tv_sec + 1e-9 * t.it_value.tv_nsec); return (t.it_value.tv_sec + 1e-9 * t.it_value.tv_nsec);
} }
/*
* Note that the contents of the BLOB returned from .id() are
* undocumented, any may change in any new version.
*/
VCL_BLOB
vmod_reader_id(VRT_CTX, struct VPFX(file_reader) *rdr)
{
time_t secs;
long nsecs;
dev_t dev;
ino_t ino;
uintptr_t snap;
struct vrt_blob *blob;
char *data;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC);
CHECK_OBJ_NOTNULL(rdr, FILE_READER_MAGIC);
CHECK_OBJ_NOTNULL(rdr->info, FILE_INFO_MAGIC);
AZ(pthread_rwlock_rdlock(&rdr->lock));
ERRCHK(ctx, rdr, "rdr", NULL);
secs = rdr->info->mtime.tv_sec;
nsecs = rdr->info->mtime.tv_nsec;
dev = rdr->info->dev;
ino = rdr->info->ino;
AZ(pthread_rwlock_unlock(&rdr->lock));
snap = WS_Snapshot(ctx->ws);
if ((blob = WS_Alloc(ctx->ws, sizeof(*blob))) == NULL) {
VFAIL(ctx, "%s.id(): insufficient workspace for blob structure",
rdr->obj_name);
return NULL;
}
if ((data = WS_Alloc(ctx->ws, sizeof(secs) + sizeof(nsecs)
+ sizeof(dev) + sizeof(ino))) == NULL) {
WS_Reset(ctx->ws, snap);
VFAIL(ctx, "%s.id(): insufficient workspace for blob data",
rdr->obj_name);
return NULL;
}
blob->type = VMOD_FILE_ID_MAGIC;
blob->len = sizeof(secs) + sizeof(nsecs) + sizeof(dev) + sizeof(ino);
blob->blob = data;
memcpy(data, &secs, sizeof(secs));
memcpy(data + sizeof(secs), &nsecs, sizeof(nsecs));
memcpy(data + sizeof(secs) + sizeof(nsecs), &dev, sizeof(dev));
memcpy(data + sizeof(secs) + sizeof(nsecs) + sizeof(dev), &ino,
sizeof(ino));
return (blob);
}
VCL_STRING VCL_STRING
vmod_version(VRT_CTX) vmod_version(VRT_CTX)
{ {
......
...@@ -411,6 +411,10 @@ Example:: ...@@ -411,6 +411,10 @@ Example::
set resp.http.Cache-Control = "public, max-age=" set resp.http.Cache-Control = "public, max-age="
+ std.integer(duration=rdr.next_check()); + std.integer(duration=rdr.next_check());
$Method BLOB .id()
XXX ...
$Function STRING version() $Function STRING version()
Return the version string for this VMOD. Return the version string for this VMOD.
......
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