Skip to content

Commit

Permalink
Copy unmodified URI to workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
duffn committed Dec 17, 2024
1 parent 5b4cadd commit e1126f0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
20 changes: 12 additions & 8 deletions src/vmod_querymodifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,24 @@ VCL_STRING vmod_modifyparams(VRT_CTX, VCL_STRING uri, VCL_STRING params_in,

CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);

// Return if the URL is NULL.
// Return if the URI is NULL.
if (uri == NULL) {
VRT_fail(ctx, "uri is NULL");
return NULL;
}

// Return if there's no query string.
// Check if there is a query string.
query_str = strchr(uri, '?');
if (query_str == NULL) {
return uri;
char *ws_uri = WS_Copy(ctx->ws, uri, strlen(uri) + 1);
if (ws_uri == NULL) {
VRT_fail(ctx,
"WS_Copy: out of workspace when returning unmodified URI");
return NULL;
}
return ws_uri;
}

// Copy the base URL up to '?' into the workspace.
size_t base_uri_len = query_str - uri;
size_t query_str_len = strlen(query_str + 1); // +1 to skip '?'
size_t new_uri_max_len =
Expand All @@ -129,13 +134,12 @@ VCL_STRING vmod_modifyparams(VRT_CTX, VCL_STRING uri, VCL_STRING params_in,
// Skip past the '?' to get the query string.
query_str = query_str + 1;

// If there are no query params, return the URL.
// If there are no query params, return the base URI from workspace.
if (*query_str == '\0') {
return new_uri;
}

// Check if params_in is an empty string and if so, return only
// the URL which removes all query params.
// If params_in is NULL or empty, remove all query params.
if (params_in == NULL || *params_in == '\0') {
return new_uri;
}
Expand Down Expand Up @@ -168,7 +172,7 @@ VCL_STRING vmod_modifyparams(VRT_CTX, VCL_STRING uri, VCL_STRING params_in,
// Tokenize the query string into parameters.
no_param = tokenize_querystring(ctx, &head, query_str_copy);
if (no_param < 0) {
VRT_fail(ctx, "tokensize_querystring: no_param: out of workspace");
VRT_fail(ctx, "tokenize_querystring failed");
return NULL;
}

Expand Down
13 changes: 11 additions & 2 deletions src/vtc/missing_params.vtc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ server s1 {
rxreq
txresp -body "OK1"
expect req.url == "/feed/?q"

rxreq
txresp -body "OK1"
expect req.url == "/sitemap.xml"
} -start

varnish v1 -vcl+backend {
Expand All @@ -26,8 +30,13 @@ client c1 {
txreq -url "/feed/?not=1&another=2&q="
rxresp
expect resp.status == 200

# This will just return the same URL since there are no parameters.
txreq -url "/sitemap.xml"
rxresp
expect resp.status == 200
} -run

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

0 comments on commit e1126f0

Please sign in to comment.