]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: h1-htx: Only use the path of a normalized URI to format a request line
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 8 Oct 2019 13:43:39 +0000 (15:43 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 9 Oct 2019 09:10:16 +0000 (11:10 +0200)
When a request start-line is converted to its raw representation, if its URI is
normalized, only the path part is used. Most of H2 clients send requests using
the absolute form (:scheme + :authority + :path), regardless the request is sent
to a proxy or not. But, when the request is relayed to an H1 origin server, it
is unusual to send it using the absolute form. And, even if the servers must
support this form, some old servers may reject it. So, for such requests, we
only get the path of the absolute URI. Most of time, it will be the right
choice. However, an option will probably by added to customize this behavior.

src/htx.c

index d8f435d447b36652b95e68f2d9058990dadcad54..c9671c12fcb1988e11c91ed9409288fb5c4e7a2b 100644 (file)
--- a/src/htx.c
+++ b/src/htx.c
@@ -1046,12 +1046,25 @@ void htx_move_blk_before(struct htx *htx, struct htx_blk **blk, struct htx_blk *
  */
 int htx_reqline_to_h1(const struct htx_sl *sl, struct buffer *chk)
 {
+       struct ist uri;
+
        if (HTX_SL_LEN(sl) + 4 > b_room(chk))
                return 0;
 
+       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("/");
+               }
+       }
+
        chunk_memcat(chk, HTX_SL_REQ_MPTR(sl), HTX_SL_REQ_MLEN(sl));
        chunk_memcat(chk, " ", 1);
-       chunk_memcat(chk, HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl));
+       chunk_memcat(chk, uri.ptr, uri.len);
        chunk_memcat(chk, " ", 1);
        if (sl->flags & HTX_SL_F_VER_11)
                chunk_memcat(chk, "HTTP/1.1", 8);