]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mux-h1: Add h1_eval_htx_hdrs_size() to estimate size of the HTX headers
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 24 May 2019 14:50:16 +0000 (16:50 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 5 Jun 2019 08:12:11 +0000 (10:12 +0200)
It is just a cosmetic change, to avoid code duplication.

src/mux_h1.c

index 18882546c5a607c785ba0fc31ad9d194aea3cab6..e89dfd3e22c82f65b89b705501a7d26a58e3cc15 100644 (file)
@@ -900,21 +900,26 @@ static void h1_set_res_tunnel_mode(struct h1s *h1s)
        }
 }
 
+/* Estimate the size of the HTX headers after the parsing, including the EOH. */
+static size_t h1_eval_htx_hdrs_size(struct http_hdr *hdrs)
+{
+       size_t sz = 0;
+       int i;
+
+       for (i = 0; hdrs[i].n.len; i++)
+               sz += sizeof(struct htx_blk) + hdrs[i].n.len + hdrs[i].v.len;
+       sz += sizeof(struct htx_blk) + 1;
+       return sz;
+}
+
 /* Estimate the size of the HTX request after the parsing. */
 static size_t h1_eval_htx_req_size(struct h1m *h1m, union h1_sl *h1sl, struct http_hdr *hdrs)
 {
        size_t sz;
-       int i;
 
        /* size of the HTX start-line */
        sz = sizeof(struct htx_sl) + h1sl->rq.m.len + h1sl->rq.u.len + h1sl->rq.v.len;
-
-       /* size of all HTX headers */
-       for (i = 0; hdrs[i].n.len; i++)
-               sz += sizeof(struct htx_blk) + hdrs[i].n.len + hdrs[i].v.len;
-
-       /* size of the EOH */
-       sz += sizeof(struct htx_blk) + 1;
+       sz += h1_eval_htx_hdrs_size(hdrs);
 
        /* size of the EOM */
        if (h1m->state == H1_MSG_DONE)
@@ -927,17 +932,10 @@ static size_t h1_eval_htx_req_size(struct h1m *h1m, union h1_sl *h1sl, struct ht
 static size_t h1_eval_htx_res_size(struct h1m *h1m, union h1_sl *h1sl, struct http_hdr *hdrs)
 {
        size_t sz;
-       int i;
 
        /* size of the HTX start-line */
        sz = sizeof(struct htx_sl) + h1sl->st.v.len + h1sl->st.c.len + h1sl->st.r.len;
-
-       /* size of all HTX headers */
-       for (i = 0; hdrs[i].n.len; i++)
-               sz += sizeof(struct htx_blk) + hdrs[i].n.len + hdrs[i].v.len;
-
-       /* size of the EOH */
-       sz += sizeof(struct htx_blk) + 1;
+       sz += h1_eval_htx_hdrs_size(hdrs);
 
        /* size of the EOM */
        if (h1m->state == H1_MSG_DONE)