From: Christopher Faulet Date: Tue, 24 Sep 2019 14:20:05 +0000 (+0200) Subject: MINOR: http: Add server name header from HTTP multiplexers X-Git-Tag: v2.1-dev2~16 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=72ba6cd8c09596381b2ef8dbb81cef2284e32242;p=thirdparty%2Fhaproxy.git MINOR: http: Add server name header from HTTP multiplexers 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). --- diff --git a/src/mux_fcgi.c b/src/mux_fcgi.c index 8094345c1f..d0fdde4356 100644 --- a/src/mux_fcgi.c +++ b/src/mux_fcgi.c @@ -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: diff --git a/src/mux_h1.c b/src/mux_h1.c index 5056fa88f9..5375ad5363 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -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; diff --git a/src/mux_h2.c b/src/mux_h2.c index 41c41deb01..2fca7ac7c6 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -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(""); diff --git a/src/stream.c b/src/stream.c index 75cacc1dcd..99e607da69 100644 --- a/src/stream.c +++ b/src/stream.c @@ -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);