Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
1ac441bc
Commit
1ac441bc
authored
Dec 16, 2014
by
Federico G. Schwindt
Committed by
Lasse Karstensen
Jan 14, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add std.time()
Converts an date in various formats to a VCL_TIME.
parent
12a6d79c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
0 deletions
+75
-0
m00020.vtc
bin/varnishtest/tests/m00020.vtc
+40
-0
vmod.vcc
lib/libvmod_std/vmod.vcc
+19
-0
vmod_std_conversions.c
lib/libvmod_std/vmod_std_conversions.c
+16
-0
No files found.
bin/varnishtest/tests/m00020.vtc
0 → 100644
View file @
1ac441bc
varnishtest "Test std.time"
server s1 {
rxreq
txresp
} -start
varnish v1 -vcl+backend {
import ${vmod_std};
sub vcl_deliver {
if (std.time(req.http.x-date, now) < now - 1y) {
set resp.http.x-past = 1;
}
if (std.time(req.http.x-date, now) > now + 1y) {
set resp.http.x-future = 1;
}
}
} -start
client c1 {
txreq -hdr "X-Date: Mon, 20 Dec 2010 00:00:00 GMT"
rxresp
expect resp.http.x-past == 1
txreq -hdr "X-Date: Monday, 20-Dec-30 00:00:00 GMT"
rxresp
expect resp.http.x-future == 1
txreq -hdr "X-Date: Mon Dec 20 00:00:00 2010"
rxresp
expect resp.http.x-past == 1
txreq -hdr "X-Date: 2030-12-20T00:00:00"
rxresp
expect resp.http.x-future == 1
txreq -hdr "X-Date: 1292803200.00"
rxresp
expect resp.http.x-past == 1
txreq -hdr "X-Date: 1923955200"
rxresp
expect resp.http.x-future == 1
} -run
lib/libvmod_std/vmod.vcc
View file @
1ac441bc
...
...
@@ -227,6 +227,25 @@ Example
| ...
| }
$Function TIME time(STRING s, TIME fallback)
Description
Converts the string *s* to a time. If conversion fails,
*fallback* will be returned.
Supported formats:
| "Sun, 06 Nov 1994 08:49:37 GMT"
| "Sunday, 06-Nov-94 08:49:37 GMT"
| "Sun Nov 6 08:49:37 1994"
| "1994-11-06T08:49:37"
| "784111777.00"
| "784111777"
Example
| if (std.time(resp.http.last-modified, now) < now - 1w) {
| ...
| }
SEE ALSO
========
...
...
lib/libvmod_std/vmod_std_conversions.c
View file @
1ac441bc
...
...
@@ -41,6 +41,7 @@
#include "vrt.h"
#include "vsa.h"
#include "vtim.h"
#include "vcc_if.h"
VCL_DURATION
__match_proto__
(
td_std_duration
)
...
...
@@ -219,3 +220,18 @@ vmod_time2real(const struct vrt_ctx *ctx, VCL_TIME t)
return
(
t
);
}
VCL_TIME
__match_proto__
(
td_std_time
)
vmod_time
(
VRT_CTX
,
VCL_STRING
p
,
VCL_TIME
d
)
{
double
r
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
if
(
p
==
NULL
)
return
(
d
);
r
=
VTIM_parse
(
p
);
if
(
r
)
return
(
r
);
return
(
vmod_real
(
ctx
,
p
,
d
));
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment