MINOR: http-htx: Add an option to eval query-string when the path is replaced
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.
diff --git a/src/http_htx.c b/src/http_htx.c
index 41211bb..c572697 100644
--- a/src/http_htx.c
+++ b/src/http_htx.c
@@ -396,10 +396,12 @@
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 @@
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 */