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
e8ffdc45
Commit
e8ffdc45
authored
Jan 29, 2019
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add the missing std.bytes() conversion function
Part of #2863
parent
f543c06b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
32 deletions
+61
-32
m00005.vtc
bin/varnishtest/tests/m00005.vtc
+41
-32
vmod.vcc
lib/libvmod_std/vmod.vcc
+9
-0
vmod_std_conversions.c
lib/libvmod_std/vmod_std_conversions.c
+11
-0
No files found.
bin/varnishtest/tests/m00005.vtc
View file @
e8ffdc45
varnishtest "Test std.duration()"
varnishtest "Test std.duration()
and std.bytes()
"
server s1 {
server s1 {
rxreq
rxreq
...
@@ -9,68 +9,77 @@ varnish v1 -vcl+backend {
...
@@ -9,68 +9,77 @@ varnish v1 -vcl+backend {
import std;
import std;
sub vcl_deliver {
sub vcl_deliver {
set resp.http.ttl = std.duration(req.http.ttl, 1s) + 1000000s;
set resp.http.duration = std.duration(req.http.duration, 1s) + 1000000s;
set resp.http.bytes = std.bytes(req.http.bytes, 10K) + 512B;
}
}
} -start
} -start
client c1 {
client c1 {
txreq -hdr "
ttl
: 0.010s"
txreq -hdr "
duration
: 0.010s"
rxresp
rxresp
expect resp.http.ttl == 1000000.010
expect resp.http.duration == 1000000.010
expect resp.http.bytes == 10752.000
txreq -hdr "
ttl: 10ms
"
txreq -hdr "
duration: 10ms" -hdr "bytes: 2k
"
rxresp
rxresp
expect resp.http.ttl == 1000000.010
expect resp.http.duration == 1000000.010
expect resp.http.bytes == 2560.000
txreq -hdr "
ttl: 10.1s
"
txreq -hdr "
duration: 10.1s" -hdr "bytes: 3 m
"
rxresp
rxresp
expect resp.http.ttl == 1000010.100
expect resp.http.duration == 1000010.100
expect resp.http.bytes == 3146240.000
txreq -hdr "
ttl: 10m
"
txreq -hdr "
duration: 10m" -hdr "bytes:4.5 g
"
rxresp
rxresp
expect resp.http.ttl == 1000600.000
expect resp.http.duration == 1000600.000
expect resp.http.bytes == 4831838720.000
txreq -hdr "
ttl: 10h
"
txreq -hdr "
duration: 10h" -hdr "bytes: 0.12 TB
"
rxresp
rxresp
expect resp.http.ttl == 1036000.000
expect resp.http.duration == 1036000.000
expect resp.http.bytes == 131941395845.000
txreq -hdr "
ttl: 10d
"
txreq -hdr "
duration: 10d" -hdr "bytes: 0.25 PB
"
rxresp
rxresp
expect resp.http.ttl == 1864000.000
expect resp.http.duration == 1864000.000
expect resp.http.bytes == 281474976711168.000
txreq -hdr "
ttl: 10w
"
txreq -hdr "
duration: 10w" -hdr "bytes: 34%
"
rxresp
rxresp
expect resp.http.ttl == 7048000.000
expect resp.http.duration == 7048000.000
expect resp.http.bytes == 10752.000
txreq -hdr "
ttl: 1y
"
txreq -hdr "
duration: 1y" -hdr "bytes: 34x
"
rxresp
rxresp
expect resp.http.ttl == 32536000.000
expect resp.http.duration == 32536000.000
expect resp.http.bytes == 10752.000
txreq -hdr "
ttl
: -100s"
txreq -hdr "
duration
: -100s"
rxresp
rxresp
expect resp.http.
ttl
== 999900.000
expect resp.http.
duration
== 999900.000
txreq -hdr "
ttl
: s"
txreq -hdr "
duration
: s"
rxresp
rxresp
expect resp.http.
ttl
== 1000001.000
expect resp.http.
duration
== 1000001.000
txreq -hdr "
ttl
: 3wx"
txreq -hdr "
duration
: 3wx"
rxresp
rxresp
expect resp.http.
ttl
== 1000001.000
expect resp.http.
duration
== 1000001.000
txreq -hdr "
ttl
: -inf"
txreq -hdr "
duration
: -inf"
rxresp
rxresp
expect resp.http.
ttl
== 1000001.000
expect resp.http.
duration
== 1000001.000
txreq -hdr "
ttl
: 2x"
txreq -hdr "
duration
: 2x"
rxresp
rxresp
expect resp.http.
ttl
== 1000001.000
expect resp.http.
duration
== 1000001.000
txreq -hdr "
ttl
: 2h x"
txreq -hdr "
duration
: 2h x"
rxresp
rxresp
expect resp.http.
ttl
== 1000001.000
expect resp.http.
duration
== 1000001.000
txreq -hdr "
ttl
: 100"
txreq -hdr "
duration
: 100"
rxresp
rxresp
expect resp.http.
ttl
== 1000001.000
expect resp.http.
duration
== 1000001.000
} -run
} -run
lib/libvmod_std/vmod.vcc
View file @
e8ffdc45
...
@@ -154,6 +154,15 @@ Description
...
@@ -154,6 +154,15 @@ Description
Example
Example
set beresp.ttl = std.duration("1w", 3600s);
set beresp.ttl = std.duration("1w", 3600s);
$Function BYTES bytes(STRING s, BYTES fallback)
Description
Converts the string *s* to bytes. *s* can be quantified
with a multiplier (k, m, g, t, p). If conversion fails,
*fallback* will be returned.
Example
std.cache_req_body(std.bytes(something.somewhere, 10K));
$Function INT integer(STRING s, INT fallback)
$Function INT integer(STRING s, INT fallback)
Description
Description
...
...
lib/libvmod_std/vmod_std_conversions.c
View file @
e8ffdc45
...
@@ -54,6 +54,17 @@ vmod_duration(VRT_CTX, VCL_STRING p, VCL_DURATION d)
...
@@ -54,6 +54,17 @@ vmod_duration(VRT_CTX, VCL_STRING p, VCL_DURATION d)
return
(
isnan
(
r
)
?
d
:
r
);
return
(
isnan
(
r
)
?
d
:
r
);
}
}
VCL_BYTES
v_matchproto_
(
td_std_bytes
)
vmod_bytes
(
VRT_CTX
,
VCL_STRING
p
,
VCL_BYTES
d
)
{
uintmax_t
r
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
if
(
VNUM_2bytes
(
p
,
&
r
,
0
)
!=
NULL
)
return
(
d
);
return
(
r
);
}
VCL_INT
v_matchproto_
(
td_std_integer
)
VCL_INT
v_matchproto_
(
td_std_integer
)
vmod_integer
(
VRT_CTX
,
VCL_STRING
p
,
VCL_INT
i
)
vmod_integer
(
VRT_CTX
,
VCL_STRING
p
,
VCL_INT
i
)
{
{
...
...
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