Skip to content

Commit

Permalink
Add excludeallparams function (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
duffn authored Jan 23, 2025
1 parent d0f0fe8 commit 64f83b9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/vmod_querymodifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,14 @@ VCL_STRING
vmod_excludeparams(VRT_CTX, VCL_STRING uri, VCL_STRING params) {
return vmod_modifyparams(ctx, uri, params, 1);
}

/**
* Exclude all query parameters from the URL.
* @param ctx The Varnish context.
* @param uri The URL to modify.
* @return The modified URL.
*/
VCL_STRING
vmod_excludeallparams(VRT_CTX, VCL_STRING uri) {
return vmod_modifyparams(ctx, uri, NULL, 1);
}
10 changes: 10 additions & 0 deletions src/vmod_querymodifier.vcc
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,13 @@ Example
::

set req.url = querymodifier.includeparams(req.url, "ts,v");

$Function STRING excludeallparams(STRING url)

Description
The function excludes all parameters in the URL.

Example
::

set req.url = querymodifier.excludeallparams(req.url);
28 changes: 28 additions & 0 deletions src/vtc/all_params_exclusion.vtc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
varnishtest "Test querymodifier vmod for all params exclusion"

server s1 {
rxreq
txresp -body "OK1"
expect req.url == "/feed/"
} -start

varnish v1 -vcl+backend {
import std;
import querymodifier;

sub vcl_recv {
std.syslog(180, "querymodifier before: " + req.url);
set req.url = querymodifier.excludeallparams(url=req.url);
std.syslog(180, "querymodifier after: " + req.url);
}
} -start

client c1 {
txreq -url "/feed/?id=1&d=2&another=3"
rxresp
expect resp.status == 200
} -run

varnish v1 -expect n_object == 1
varnish v1 -expect cache_miss == 1
varnish v1 -expect cache_hit == 0

0 comments on commit 64f83b9

Please sign in to comment.