mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-11-28 06:11:32 +01:00
MEDIUM: proxy: Store server_id_hdr_name as a struct ist
The server_id_hdr_name is already processed as an ist in various locations lets
also just store it as such.
see 0643b0e7e ("MINOR: proxy: Make `header_unique_id` a `struct ist`") for a
very similar past commit.
This commit is contained in:
parent
e502c3e793
commit
b4b03779d0
@ -354,8 +354,7 @@ struct proxy {
|
||||
struct net_addr except_xot_net; /* don't x-original-to for this address. */
|
||||
struct ist fwdfor_hdr_name; /* header to use - default: "x-forwarded-for" */
|
||||
struct ist orgto_hdr_name; /* header to use - default: "x-original-to" */
|
||||
char *server_id_hdr_name; /* the header to use to send the server id (name) */
|
||||
int server_id_hdr_len; /* the length of the id (name) header... name */
|
||||
struct ist server_id_hdr_name; /* the header to use to send the server id (name) */
|
||||
int conn_retries; /* maximum number of connect retries */
|
||||
unsigned int retry_type; /* Type of retry allowed */
|
||||
int redispatch_after; /* number of retries before redispatch */
|
||||
|
||||
@ -1383,12 +1383,11 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
|
||||
}
|
||||
|
||||
/* set the desired header name, in lower case */
|
||||
free(curproxy->server_id_hdr_name);
|
||||
curproxy->server_id_hdr_name = strdup(args[1]);
|
||||
if (!curproxy->server_id_hdr_name)
|
||||
istfree(&curproxy->server_id_hdr_name);
|
||||
curproxy->server_id_hdr_name = istdup(ist(args[1]));
|
||||
if (!isttest(curproxy->server_id_hdr_name))
|
||||
goto alloc_error;
|
||||
curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name);
|
||||
ist2bin_lc(curproxy->server_id_hdr_name, ist2(curproxy->server_id_hdr_name, curproxy->server_id_hdr_len));
|
||||
ist2bin_lc(istptr(curproxy->server_id_hdr_name), curproxy->server_id_hdr_name);
|
||||
}
|
||||
else if (strcmp(args[0], "block") == 0) {
|
||||
ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. Use 'http-request deny' which uses the exact same syntax.\n", file, linenum, args[0]);
|
||||
|
||||
@ -2043,8 +2043,7 @@ static size_t fcgi_strm_send_params(struct fcgi_conn *fconn, struct fcgi_strm *f
|
||||
}
|
||||
|
||||
/* Skip header if same name is used to add the server name */
|
||||
if (fconn->proxy->server_id_hdr_name &&
|
||||
isteq(p.n, ist2(fconn->proxy->server_id_hdr_name, fconn->proxy->server_id_hdr_len)))
|
||||
if (isttest(fconn->proxy->server_id_hdr_name) && isteq(p.n, fconn->proxy->server_id_hdr_name))
|
||||
break;
|
||||
|
||||
memcpy(trash.area, "http_", 5);
|
||||
@ -2062,15 +2061,15 @@ 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) {
|
||||
if (isttest(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.n = ist2(trash.area, 0);
|
||||
istcat(&p.n, ist("http_"), trash.size);
|
||||
istcat(&p.n, fconn->proxy->server_id_hdr_name, trash.size);
|
||||
p.v = ist(srv->id);
|
||||
|
||||
if (!fcgi_encode_param(&outbuf, &p)) {
|
||||
|
||||
@ -2143,8 +2143,8 @@ static size_t h1_process_mux(struct h1c *h1c, struct buffer *buf, size_t count)
|
||||
}
|
||||
|
||||
/* Skip header if same name is used to add the server name */
|
||||
if (!(h1m->flags & H1_MF_RESP) && h1c->px->server_id_hdr_name &&
|
||||
isteqi(n, ist2(h1c->px->server_id_hdr_name, h1c->px->server_id_hdr_len)))
|
||||
if (!(h1m->flags & H1_MF_RESP) && isttest(h1c->px->server_id_hdr_name) &&
|
||||
isteqi(n, h1c->px->server_id_hdr_name))
|
||||
goto skip_hdr;
|
||||
|
||||
/* Try to adjust the case of the header name */
|
||||
@ -2213,11 +2213,11 @@ static size_t h1_process_mux(struct h1c *h1c, struct buffer *buf, size_t count)
|
||||
|
||||
/* 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) {
|
||||
!(h1m->flags & H1_MF_RESP) && isttest(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);
|
||||
n = h1c->px->server_id_hdr_name;
|
||||
v = ist(srv->id);
|
||||
|
||||
/* Try to adjust the case of the header name */
|
||||
|
||||
@ -5349,8 +5349,8 @@ static size_t h2s_bck_make_req_headers(struct h2s *h2s, struct htx *htx)
|
||||
list[hdr].v = htx_get_blk_value(htx, blk);
|
||||
|
||||
/* Skip header if same name is used to add the server name */
|
||||
if ((h2c->flags & H2_CF_IS_BACK) && h2c->proxy->server_id_hdr_name &&
|
||||
isteq(list[hdr].n, ist2(h2c->proxy->server_id_hdr_name, h2c->proxy->server_id_hdr_len)))
|
||||
if ((h2c->flags & H2_CF_IS_BACK) && isttest(h2c->proxy->server_id_hdr_name) &&
|
||||
isteq(list[hdr].n, h2c->proxy->server_id_hdr_name))
|
||||
continue;
|
||||
|
||||
/* Convert connection: upgrade to Extended connect from rfc 8441 */
|
||||
@ -5416,11 +5416,11 @@ static size_t h2s_bck_make_req_headers(struct h2s *h2s, struct htx *htx)
|
||||
BUG_ON(!sl);
|
||||
|
||||
/* Now add the server name to a header (if requested) */
|
||||
if ((h2c->flags & H2_CF_IS_BACK) && h2c->proxy->server_id_hdr_name) {
|
||||
if ((h2c->flags & H2_CF_IS_BACK) && isttest(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].n = h2c->proxy->server_id_hdr_name;
|
||||
list[hdr].v = ist(srv->id);
|
||||
hdr++;
|
||||
}
|
||||
|
||||
@ -1441,7 +1441,7 @@ void proxy_free_defaults(struct proxy *defproxy)
|
||||
ha_free(&defproxy->conn_src.iface_name);
|
||||
istfree(&defproxy->fwdfor_hdr_name);
|
||||
istfree(&defproxy->orgto_hdr_name);
|
||||
ha_free(&defproxy->server_id_hdr_name); defproxy->server_id_hdr_len = 0;
|
||||
istfree(&defproxy->server_id_hdr_name);
|
||||
|
||||
list_for_each_entry_safe(acl, aclb, &defproxy->acl, list) {
|
||||
LIST_DELETE(&acl->list);
|
||||
@ -1607,10 +1607,8 @@ static int proxy_defproxy_cpy(struct proxy *curproxy, const struct proxy *defpro
|
||||
if (isttest(defproxy->orgto_hdr_name))
|
||||
curproxy->orgto_hdr_name = istdup(defproxy->orgto_hdr_name);
|
||||
|
||||
if (defproxy->server_id_hdr_len) {
|
||||
curproxy->server_id_hdr_len = defproxy->server_id_hdr_len;
|
||||
curproxy->server_id_hdr_name = strdup(defproxy->server_id_hdr_name);
|
||||
}
|
||||
if (isttest(defproxy->server_id_hdr_name))
|
||||
curproxy->server_id_hdr_name = istdup(defproxy->server_id_hdr_name);
|
||||
|
||||
/* initialize error relocations */
|
||||
if (!proxy_dup_default_conf_errors(curproxy, defproxy, &tmpmsg)) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user