Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add excludeallparams function #10

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading