[master] d35ed6e Add 'ms' conversion qualifier to std.duration

Martin Blix Grydeland martin at varnish-software.com
Mon Feb 24 13:50:14 CET 2014


commit d35ed6e2617203a0ce9d5cd27bb2286720efab73
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Mon Feb 24 13:48:38 2014 +0100

    Add 'ms' conversion qualifier to std.duration
    
    Add 'ms' conversion qualifier to std.duration, and update
    documentation and test case.
    
    Fixes: #1434

diff --git a/bin/varnishtest/tests/m00005.vtc b/bin/varnishtest/tests/m00005.vtc
index aa7143d..53f5ae3 100644
--- a/bin/varnishtest/tests/m00005.vtc
+++ b/bin/varnishtest/tests/m00005.vtc
@@ -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
diff --git a/lib/libvmod_std/vmod.vcc b/lib/libvmod_std/vmod.vcc
index a55371c..baeb48f 100644
--- a/lib/libvmod_std/vmod.vcc
+++ b/lib/libvmod_std/vmod.vcc
@@ -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);
 
diff --git a/lib/libvmod_std/vmod_std_conversions.c b/lib/libvmod_std/vmod_std_conversions.c
index f9cba84..b9020d1 100644
--- a/lib/libvmod_std/vmod_std_conversions.c
+++ b/lib/libvmod_std/vmod_std_conversions.c
@@ -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;



More information about the varnish-commit mailing list