Skip to content

Commit c094ee7

Browse files
authoredDec 17, 2024··
Copy unmodified URI to workspace (#5)
1 parent 5b4cadd commit c094ee7

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed
 

‎src/vmod_querymodifier.c

+12-8
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,24 @@ VCL_STRING vmod_modifyparams(VRT_CTX, VCL_STRING uri, VCL_STRING params_in,
9898

9999
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
100100

101-
// Return if the URL is NULL.
101+
// Return if the URI is NULL.
102102
if (uri == NULL) {
103103
VRT_fail(ctx, "uri is NULL");
104104
return NULL;
105105
}
106106

107-
// Return if there's no query string.
107+
// Check if there is a query string.
108108
query_str = strchr(uri, '?');
109109
if (query_str == NULL) {
110-
return uri;
110+
char *ws_uri = WS_Copy(ctx->ws, uri, strlen(uri) + 1);
111+
if (ws_uri == NULL) {
112+
VRT_fail(ctx,
113+
"WS_Copy: out of workspace when returning unmodified URI");
114+
return NULL;
115+
}
116+
return ws_uri;
111117
}
112118

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

132-
// If there are no query params, return the URL.
137+
// If there are no query params, return the base URI from workspace.
133138
if (*query_str == '\0') {
134139
return new_uri;
135140
}
136141

137-
// Check if params_in is an empty string and if so, return only
138-
// the URL which removes all query params.
142+
// If params_in is NULL or empty, remove all query params.
139143
if (params_in == NULL || *params_in == '\0') {
140144
return new_uri;
141145
}
@@ -168,7 +172,7 @@ VCL_STRING vmod_modifyparams(VRT_CTX, VCL_STRING uri, VCL_STRING params_in,
168172
// Tokenize the query string into parameters.
169173
no_param = tokenize_querystring(ctx, &head, query_str_copy);
170174
if (no_param < 0) {
171-
VRT_fail(ctx, "tokensize_querystring: no_param: out of workspace");
175+
VRT_fail(ctx, "tokenize_querystring failed");
172176
return NULL;
173177
}
174178

‎src/vtc/missing_params.vtc

+11-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ server s1 {
44
rxreq
55
txresp -body "OK1"
66
expect req.url == "/feed/?q"
7+
8+
rxreq
9+
txresp -body "OK1"
10+
expect req.url == "/sitemap.xml"
711
} -start
812

913
varnish v1 -vcl+backend {
@@ -26,8 +30,13 @@ client c1 {
2630
txreq -url "/feed/?not=1&another=2&q="
2731
rxresp
2832
expect resp.status == 200
33+
34+
# This will just return the same URL since there are no parameters.
35+
txreq -url "/sitemap.xml"
36+
rxresp
37+
expect resp.status == 200
2938
} -run
3039

31-
varnish v1 -expect n_object == 1
32-
varnish v1 -expect cache_miss == 1
40+
varnish v1 -expect n_object == 2
41+
varnish v1 -expect cache_miss == 2
3342
varnish v1 -expect cache_hit == 1

0 commit comments

Comments
 (0)
Please sign in to comment.