Skip to content

Commit 64f83b9

Browse files
authored
Add excludeallparams function (#10)
1 parent d0f0fe8 commit 64f83b9

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

src/vmod_querymodifier.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,14 @@ VCL_STRING
298298
vmod_excludeparams(VRT_CTX, VCL_STRING uri, VCL_STRING params) {
299299
return vmod_modifyparams(ctx, uri, params, 1);
300300
}
301+
302+
/**
303+
* Exclude all query parameters from the URL.
304+
* @param ctx The Varnish context.
305+
* @param uri The URL to modify.
306+
* @return The modified URL.
307+
*/
308+
VCL_STRING
309+
vmod_excludeallparams(VRT_CTX, VCL_STRING uri) {
310+
return vmod_modifyparams(ctx, uri, NULL, 1);
311+
}

src/vmod_querymodifier.vcc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,13 @@ Example
3838
::
3939

4040
set req.url = querymodifier.includeparams(req.url, "ts,v");
41+
42+
$Function STRING excludeallparams(STRING url)
43+
44+
Description
45+
The function excludes all parameters in the URL.
46+
47+
Example
48+
::
49+
50+
set req.url = querymodifier.excludeallparams(req.url);

src/vtc/all_params_exclusion.vtc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
varnishtest "Test querymodifier vmod for all params exclusion"
2+
3+
server s1 {
4+
rxreq
5+
txresp -body "OK1"
6+
expect req.url == "/feed/"
7+
} -start
8+
9+
varnish v1 -vcl+backend {
10+
import std;
11+
import querymodifier;
12+
13+
sub vcl_recv {
14+
std.syslog(180, "querymodifier before: " + req.url);
15+
set req.url = querymodifier.excludeallparams(url=req.url);
16+
std.syslog(180, "querymodifier after: " + req.url);
17+
}
18+
} -start
19+
20+
client c1 {
21+
txreq -url "/feed/?id=1&d=2&another=3"
22+
rxresp
23+
expect resp.status == 200
24+
} -run
25+
26+
varnish v1 -expect n_object == 1
27+
varnish v1 -expect cache_miss == 1
28+
varnish v1 -expect cache_hit == 0

0 commit comments

Comments
 (0)