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).
This commit is contained in:
Christopher Faulet 2019-09-24 16:20:05 +02:00
parent b1bb1afa47
commit 72ba6cd8c0
4 changed files with 45 additions and 10 deletions

View 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:

View 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;

View 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("");

View 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);