]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: checks: Keep the Host header and the request uri synchronized
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 29 Apr 2020 11:21:37 +0000 (13:21 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 29 Apr 2020 11:32:29 +0000 (13:32 +0200)
Because in HTTP, the host header and the request authority, if any, must be
identical, we keep both synchornized. It means the right flags are set on the
HTX statrt-line calling http_update_host(). There is no header when it happens,
but it is not an issue. Then, if a Host header is inserted,
http_update_authority() is called.

Note that for now, the host header is not automatically added when required.

src/checks.c

index 3b22adabfdb558182565d9b81110a9974a466ffa..7c75a1d84290e015b50f678bab92fbd9189d0a89 100644 (file)
@@ -1930,6 +1930,8 @@ static enum tcpcheck_eval_ret tcpcheck_eval_send(struct check *check, struct tcp
                if (!sl)
                        goto error_htx;
                sl->info.req.meth = send->http.meth.meth;
+               if (!http_update_host(htx, sl, uri))
+                       goto error_htx;
 
                body = send->http.body; // TODO: handle body_fmt
                clen = ist((!istlen(body) ? "0" : ultoa(istlen(body))));
@@ -1940,14 +1942,20 @@ static enum tcpcheck_eval_ret tcpcheck_eval_send(struct check *check, struct tcp
 
                if (!LIST_ISEMPTY(&send->http.hdrs)) {
                        struct tcpcheck_http_hdr *hdr;
+                       struct ist hdr_value;
 
                        list_for_each_entry(hdr, &send->http.hdrs, list) {
                                chunk_reset(tmp);
                                 tmp->data = sess_build_logline(check->sess, NULL, b_orig(tmp), b_size(tmp), &hdr->value);
                                if (!b_data(tmp))
                                        continue;
-                               if (!htx_add_header(htx, hdr->name, ist2(b_orig(tmp), b_data(tmp))))
+                               hdr_value = ist2(b_orig(tmp), b_data(tmp));
+                               if (!htx_add_header(htx, hdr->name, hdr_value))
                                        goto error_htx;
+                               if ((sl->flags & HTX_SL_F_HAS_AUTHORITY) && isteqi(hdr->name, ist("host"))) {
+                                       if (!http_update_authority(htx, sl, hdr_value))
+                                               goto error_htx;
+                               }
                        }
 
                }