BUG/MINOR: mux-fcgi: Don't send normalized uri to FCGI application master
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 26 Apr 2021 07:38:55 +0000 (09:38 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 29 Apr 2021 10:02:51 +0000 (12:02 +0200)
A normalized URI is the internal term used to specify an URI is stored using
the absolute format (scheme + authority + path). For now, it is only used
for H2 clients. It is the default and recommended format for H2 request.
However, it is unusual for H1 servers to receive such URI. So in this case,
we only send the path of the absolute URI. It is performed for H1 servers,
but not for FCGI applications. This patch fixes the difference.

Note that it is not a real bug, because FCGI applications should support
abosolute URI.

Note also a normalized URI is only detected for H2 clients when a request is
received. There is no such test on the H1 side. It means an absolute URI
received from an H1 client will be sent without modification to an H1 server
or a FCGI application.

To make it possible, a dedicated function has been added to get the H1
URI. This function is called by the H1 and the FCGI multiplexer when a
request is sent to a server.

This patch should fix the issue #1232. It must be backported as far as 2.2.

(cherry picked from commit fb38c910f8f2bdf1b32ec74824d8f8a8f9a29a8f)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit bdda8452cb74f3d2e752c4cd208f5444c1a6993b)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit dd6a24d5b84d7cf0cd07b44cd363c19d9a66bb32)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

include/proto/h1_htx.h
src/h1_htx.c
src/mux_fcgi.c

index e77663b..91587c5 100644 (file)
@@ -26,6 +26,7 @@
 #include <common/buf.h>
 #include <common/ist.h>
 #include <common/h1.h>
+#include <common/htx.h>
 
 int h1_parse_msg_hdrs(struct h1m *h1m, union h1_sl *h1sl, struct htx *dsthtx,
                      struct buffer *srcbuf, size_t ofs, size_t max);
@@ -35,6 +36,29 @@ int h1_parse_msg_data(struct h1m *h1m, struct htx **dsthtx,
 int h1_parse_msg_tlrs(struct h1m *h1m, struct htx *dsthtx,
                      struct buffer *srcbuf, size_t ofs, size_t max);
 
+/* Returns the URI of an HTX message in the most common format for a H1 peer. It
+ * is the path part of an absolute URI when the URI was normalized, ortherwise
+ * it is the whole URI, as received. Concretely, it is only a special case for
+ * URIs received from H2 clients, to be able to send a relative path the H1
+ * servers.
+ */
+static inline struct ist h1_get_uri(const struct htx_sl *sl)
+{
+       struct ist uri;
+
+       uri = htx_sl_req_uri(sl);
+       if (sl->flags & HTX_SL_F_NORMALIZED_URI) {
+               uri = http_get_path(uri);
+               if (unlikely(!uri.len)) {
+                       if (sl->info.req.meth == HTTP_METH_OPTIONS)
+                               uri = ist("*");
+                       else
+                               uri = ist("/");
+               }
+       }
+       return uri;
+}
+
 int h1_format_htx_reqline(const struct htx_sl *sl, struct buffer *chk);
 int h1_format_htx_stline(const struct htx_sl *sl, struct buffer *chk);
 int h1_format_htx_hdr(const struct ist n, const struct ist v, struct buffer *chk);
index 48bfae5..d56b493 100644 (file)
@@ -612,17 +612,7 @@ int h1_format_htx_reqline(const struct htx_sl *sl, struct buffer *chk)
        struct ist uri;
        size_t sz = chk->data;
 
-       uri = htx_sl_req_uri(sl);
-       if (sl->flags & HTX_SL_F_NORMALIZED_URI) {
-               uri = http_get_path(uri);
-               if (unlikely(!uri.len)) {
-                       if (sl->info.req.meth == HTTP_METH_OPTIONS)
-                               uri = ist("*");
-                       else
-                               uri = ist("/");
-               }
-       }
-
+       uri = h1_get_uri(sl);
        if (!chunk_memcat(chk, HTX_SL_REQ_MPTR(sl), HTX_SL_REQ_MLEN(sl)) ||
            !chunk_memcat(chk, " ", 1) ||
            !chunk_memcat(chk, uri.ptr, uri.len) ||
index a529e2f..5654f40 100644 (file)
@@ -1243,7 +1243,7 @@ static int fcgi_set_default_param(struct fcgi_conn *fconn, struct fcgi_strm *fst
                chunk_memcat(params->p, p.ptr, p.len);
        }
        if (!(params->mask & FCGI_SP_REQ_URI)) {
-               p  = htx_sl_req_uri(sl);
+               p = h1_get_uri(sl);
                params->uri = ist2(b_tail(params->p), p.len);
                chunk_memcat(params->p, p.ptr, p.len);
        }