Commit d35ed6e2 authored by Martin Blix Grydeland's avatar Martin Blix Grydeland

Add 'ms' conversion qualifier to std.duration

Add 'ms' conversion qualifier to std.duration, and update
documentation and test case.

Fixes: #1434
parent 2f580e27
......@@ -19,6 +19,12 @@ varnish v1 -vcl+backend {
} -start
client c1 {
txreq -url "/1" -hdr "ttl: 10ms "
rxresp
expect resp.status == 200
expect resp.http.ttl == 1000001.010
expect resp.bodylen == 1
txreq -url "/1" -hdr "ttl: 10s "
rxresp
expect resp.status == 200
......
......@@ -112,9 +112,9 @@ $Function DURATION duration(STRING, DURATION)
Description
Converts the string *s* to seconds. *s* must be quantified
with the usual s (seconds), m (minutes), h (hours), d (days)
and w (weeks) units. If *s* fails to parse, *fallback* will be
returned.
with the usual ms (milliseconds), s (seconds), m (minutes), h
(hours), d (days) and w (weeks) units. If *s* fails to parse,
*fallback* will be returned.
Example
set beresp.ttl = std.duration("1w", 3600s);
......
......@@ -76,7 +76,13 @@ vmod_duration(const struct vrt_ctx *ctx, const char *p, VCL_DURATION d)
/* NB: Keep this list synchronized with VCC */
switch (*e++) {
case 's': break;
case 'm': r *= 60.; break;
case 'm':
if (*e == 's') {
r *= 1e-3;
e++;
} else
r *= 60.;
break;
case 'h': r *= 60.*60.; break;
case 'd': r *= 60.*60.*24.; break;
case 'w': r *= 60.*60.*24.*7.; break;
......
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