diff --git a/src/mux_fcgi.c b/src/mux_fcgi.c index 8094345c1..d0fdde435 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 5056fa88f..5375ad536 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 41c41deb0..2fca7ac7c 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 75cacc1dc..99e607da6 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);