]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http: Add server name header from HTTP multiplexers
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 24 Sep 2019 14:20:05 +0000 (16:20 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 27 Sep 2019 06:48:21 +0000 (08:48 +0200)
the option "http-send-name-header" is an eyesore. It was responsible of several
bugs because it is handled after the message analysis. With the HTX
representation, the situation is cleaner because no rewind on forwarded data is
required. But it remains ugly.

With recent changes in HAProxy, we have the opportunity to make it fairly
better. The message formatting in now done in the HTTP multiplexers. So it seems
to be the right place to handle this option. Now, the server name is added by
the HTTP multiplexers (h1, h2 and fcgi).

src/mux_fcgi.c
src/mux_h1.c
src/mux_h2.c
src/stream.c

index 8094345c1fc461d38df01763729ebaf085c416a2..d0fdde43568ed7f179d02c96b54908531566e820 100644 (file)
@@ -1603,6 +1603,24 @@ static size_t fcgi_strm_send_params(struct fcgi_conn *fconn, struct fcgi_strm *f
                                break;
 
                        case HTX_BLK_EOH:
+                               if (fconn->proxy->server_id_hdr_name) {
+                                       struct server *srv = objt_server(fconn->conn->target);
+
+                                       if (!srv)
+                                               goto done;
+
+                                       memcpy(trash.area, "http_", 5);
+                                       memcpy(trash.area+5, fconn->proxy->server_id_hdr_name, fconn->proxy->server_id_hdr_len);
+                                       p.n = ist2(trash.area, fconn->proxy->server_id_hdr_len+5);
+                                       p.v = ist(srv->id);
+
+                                       if (!fcgi_encode_param(&outbuf, &p)) {
+                                               if (b_space_wraps(mbuf))
+                                                       goto realign_again;
+                                               if (outbuf.data == 8)
+                                                       goto full;
+                                       }
+                               }
                                goto done;
 
                        default:
index 5056fa88f9c508b13b79ab4f64ba1e9b49abd215..5375ad536373e59a3a3dac9ba2f9e93e4562da6b 100644 (file)
@@ -70,7 +70,8 @@
 #define H1S_F_SPLICED_DATA   0x00000200 /* Set when the kernel splicing is in used */
 #define H1S_F_HAVE_I_TLR     0x00000800 /* Set during input process to know the trailers were processed */
 #define H1S_F_APPEND_EOM     0x00001000 /* Send EOM to the HTX buffer */
-/* 0x00002000 .. 0x00002000 unused */
+/* 0x00002000 .. 0x00001000 unused */
+#define H1S_F_HAVE_SRV_NAME  0x00002000 /* Set during output process if the server name header was added to the request */
 #define H1S_F_HAVE_O_CONN    0x00004000 /* Set during output process to know connection mode was processed */
 
 /* H1 connection descriptor */
@@ -1331,6 +1332,20 @@ static size_t h1_process_output(struct h1c *h1c, struct buffer *buf, size_t coun
                                        h1m->flags |= H1_MF_CHNK;
                                }
 
+                               /* Now add the server name to a header (if requested) */
+                               if (!(h1s->flags & H1S_F_HAVE_SRV_NAME) &&
+                                   !(h1m->flags & H1_MF_RESP) && h1c->px->server_id_hdr_name) {
+                                       struct server *srv = objt_server(h1c->conn->target);
+
+                                       if (srv) {
+                                               n = ist2(h1c->px->server_id_hdr_name, h1c->px->server_id_hdr_len);
+                                               v = ist(srv->id);
+                                               if (!htx_hdr_to_h1(n, v, &tmp))
+                                                       goto copy;
+                                       }
+                                       h1s->flags |= H1S_F_HAVE_SRV_NAME;
+                               }
+
                                if (!chunk_memcat(&tmp, "\r\n", 2))
                                        goto copy;
 
index 41c41deb01d71afb7f8dde03fa33a7bbd6efda4a..2fca7ac7c6192ec875c66022bc3e861835e13f0c 100644 (file)
@@ -4739,6 +4739,17 @@ static size_t h2s_bck_make_req_headers(struct h2s *h2s, struct htx *htx)
                hdr++;
        }
 
+       /* Now add the server name to a header (if requested) */
+       if ((h2c->flags & H2_CF_IS_BACK) && h2c->proxy->server_id_hdr_name) {
+               struct server *srv = objt_server(h2c->conn->target);
+
+               if (srv) {
+                       list[hdr].n = ist2(h2c->proxy->server_id_hdr_name, h2c->proxy->server_id_hdr_len);
+                       list[hdr].v = ist(srv->id);
+                       hdr++;
+               }
+       }
+
        /* marker for end of headers */
        list[hdr].n = ist("");
 
index 75cacc1dcdf76b2f8d155474064f69d431e9ae84..99e607da691fe63f98261be9294c6465da6527e2 100644 (file)
@@ -2389,15 +2389,6 @@ struct task *process_stream(struct task *t, void *context, unsigned short state)
                        if (unlikely(si_b->state == SI_ST_EST))
                                sess_establish(s);
 
-                       /* Now we can add the server name to a header (if requested) */
-                       /* check for HTTP mode and proxy server_name_hdr_name != NULL */
-                       if (si_state_in(si_b->state, SI_SB_CON|SI_SB_RDY|SI_SB_EST) &&
-                           (s->be->server_id_hdr_name != NULL) &&
-                           (s->be->mode == PR_MODE_HTTP) &&
-                           objt_server(s->target)) {
-                               http_send_name_header(s, s->be, objt_server(s->target)->id);
-                       }
-
                        srv = objt_server(s->target);
                        if (si_b->state == SI_ST_ASS && srv && srv->rdr_len && (s->flags & SF_REDIRECTABLE))
                                http_perform_server_redirect(s, si_b);