MINOR: uri_normalizer: Add a `merge-slashes` normalizer to http-request normalize-uri
This normalizer merges adjacent slashes into a single slash, thus removing
empty path segments.
See GitHub Issue #714.
diff --git a/src/http_act.c b/src/http_act.c
index 134c903..2af4d47 100644
--- a/src/http_act.c
+++ b/src/http_act.c
@@ -215,8 +215,23 @@
goto fail_alloc;
switch ((enum act_normalize_uri) rule->action) {
- case ACT_NORMALIZE_URI_PLACEHOLDER:
- (void) uri;
+ case ACT_NORMALIZE_URI_MERGE_SLASHES: {
+ const struct ist path = http_get_path(uri);
+ struct ist newpath = ist2(replace->area, replace->size);
+
+ if (!isttest(path))
+ goto leave;
+
+ err = uri_normalizer_path_merge_slashes(iststop(path, '?'), &newpath);
+
+ if (err != URI_NORMALIZER_ERR_NONE)
+ break;
+
+ if (!http_replace_req_path(htx, newpath, 0))
+ goto fail_rewrite;
+
+ break;
+ }
}
switch (err) {
@@ -277,8 +292,10 @@
return ACT_RET_PRS_ERR;
}
- if (0) {
+ if (strcmp(args[cur_arg], "merge-slashes") == 0) {
+ cur_arg++;
+ rule->action = ACT_NORMALIZE_URI_MERGE_SLASHES;
}
else {
memprintf(err, "unknown normalizer '%s'", args[cur_arg]);