]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http-htx: Add an option to eval query-string when the path is replaced
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 31 Aug 2020 14:11:57 +0000 (16:11 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 1 Sep 2020 08:55:14 +0000 (10:55 +0200)
The http_replace_req_path() function now takes a third argument to evaluate the
query-string as part of the path or to preserve it. If <with_qs> is set, the
query-string is replaced with the path. Otherwise, only the path is replaced.

This patch is mandatory to fix issue #829. The next commit depends on it. So be
carefull during backports.

include/haproxy/http_htx.h
src/http_ana.c
src/http_htx.c

index 4b0f09744edd42a2a77f5107e5926815741bcd8c..a02c65c009fa66edc9891e786db838f2067dc3d5 100644 (file)
@@ -45,7 +45,7 @@ int http_add_header(struct htx *htx, const struct ist n, const struct ist v);
 int http_replace_stline(struct htx *htx, const struct ist p1, const struct ist p2, const struct ist p3);
 int http_replace_req_meth(struct htx *htx, const struct ist meth);
 int http_replace_req_uri(struct htx *htx, const struct ist uri);
-int http_replace_req_path(struct htx *htx, const struct ist path);
+int http_replace_req_path(struct htx *htx, const struct ist path, int with_qs);
 int http_replace_req_query(struct htx *htx, const struct ist query);
 int http_replace_res_status(struct htx *htx, const struct ist status);
 int http_replace_res_reason(struct htx *htx, const struct ist reason);
index 39f75de233ce6ee7a883c2a34baf1bce8594cb42..43c2145bd11aba57c84c6faa979440f1ac97b3bc 100644 (file)
@@ -2771,7 +2771,7 @@ int http_req_replace_stline(int action, const char *replace, int len,
                        break;
 
                case 1: // path
-                       if (!http_replace_req_path(htx, ist2(replace, len)))
+                       if (!http_replace_req_path(htx, ist2(replace, len), 0))
                                return -1;
                        break;
 
index 41211bb8ff01690dc4b918a7da16d6d6aa3c9960..c572697bed118d7a601b30b56eb20e7eb84a2e9b 100644 (file)
@@ -396,10 +396,12 @@ int http_replace_req_uri(struct htx *htx, const struct ist uri)
        return 0;
 }
 
-/* Replace the request path in the HTX message <htx> by <path>. The host part
- * and the query string are preserved. It returns 1 on success, otherwise 0.
+/* Replace the request path in the HTX message <htx> by <path>. The host part is
+ * preserverd. if <with_qs> is set, the query string is evaluated as part of the
+ * path and replaced. Otherwise, it is preserved too. It returns 1 on success,
+ * otherwise 0.
  */
-int http_replace_req_path(struct htx *htx, const struct ist path)
+int http_replace_req_path(struct htx *htx, const struct ist path, int with_qs)
 {
        struct buffer *temp = get_trash_chunk();
        struct htx_sl *sl = http_get_stline(htx);
@@ -413,8 +415,12 @@ int http_replace_req_path(struct htx *htx, const struct ist path)
        p = http_get_path(uri);
        if (!isttest(p))
                p = uri;
-       while (plen < p.len && *(p.ptr + plen) != '?')
-               plen++;
+       if (with_qs)
+               plen = p.len;
+       else {
+               while (plen < p.len && *(p.ptr + plen) != '?')
+                       plen++;
+       }
 
        /* Start by copying old method and version and create the new uri */
        chunk_memcat(temp, HTX_SL_REQ_MPTR(sl), HTX_SL_REQ_MLEN(sl)); /* meth */