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.
---
include/haproxy/proxy-t.h | 3 +--
src/cfgparse-listen.c | 9 ++++-----
src/mux_fcgi.c | 11 +++++------
src/mux_h1.c | 8 ++++----
src/mux_h2.c | 8 ++++----
src/proxy.c | 8 +++-----
6 files changed, 21 insertions(+), 26 deletions(-)
diff --git a/include/haproxy/proxy-t.h b/include/haproxy/proxy-t.h
index 805e1b452..80431757e 100644
--- a/include/haproxy/proxy-t.h
+++ b/include/haproxy/proxy-t.h
@@ -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 */
diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c
index 121f1deac..216e6d8d5 100644
--- a/src/cfgparse-listen.c
+++ b/src/cfgparse-listen.c
@@ -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]);
diff --git a/src/mux_fcgi.c b/src/mux_fcgi.c
index b5b280749..a22bc9391 100644
--- a/src/mux_fcgi.c
+++ b/src/mux_fcgi.c
@@ -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)) {
diff --git a/src/mux_h1.c b/src/mux_h1.c
index 7de086255..3ddf6ef86 100644
--- a/src/mux_h1.c
+++ b/src/mux_h1.c
@@ -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 */
diff --git a/src/mux_h2.c b/src/mux_h2.c
index 4fed9b2df..0c312ba19 100644
--- a/src/mux_h2.c
+++ b/src/mux_h2.c
@@ -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++;
}
diff --git a/src/proxy.c b/src/proxy.c
index f051768ac..c6a1e0dfe 100644
--- a/src/proxy.c
+++ b/src/proxy.c
@@ -1437,7 +1437,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);
@@ -1603,10 +1603,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)) {
--
2.35.1