]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: htx: Don't use end-of-data blocks anymore
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 4 Jun 2019 08:08:28 +0000 (10:08 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 5 Jun 2019 08:12:11 +0000 (10:12 +0200)
This type of blocks is useless because transition between data and trailers is
obvious. And when there is no trailers, the end-of-message is still there to
know when data end for chunked messages.

contrib/prometheus-exporter/service-prometheus.c
include/common/htx.h
src/flt_http_comp.c
src/hlua.c
src/http_fetch.c
src/htx.c
src/mux_h1.c
src/mux_h2.c
src/proto_htx.c
src/stats.c

index 483e7031f18c16d009ab2696d296f358fedaecc7..c55233727bef71b08a962520cf0bc1081fa46719 100644 (file)
@@ -2186,7 +2186,7 @@ static void promex_appctx_handle_io(struct appctx *appctx)
                        /* fall through */
 
                case PROMEX_ST_DONE:
-                       /* Don't add EOD and TLR because mux-h1 will take care of it */
+                       /* Don't add TLR because mux-h1 will take care of it */
                        if (!htx_add_endof(res_htx, HTX_BLK_EOM)) {
                                si_rx_room_blk(si);
                                goto out;
index e2d4e15a116473a50912861a59718a767d4a5c15..cb998b99e6db69cef65cbe0e1ab28e88957b0c30 100644 (file)
@@ -101,10 +101,9 @@ enum htx_blk_type {
        HTX_BLK_HDR    =  2, /* header name/value block */
        HTX_BLK_EOH    =  3, /* end-of-headers block */
        HTX_BLK_DATA   =  4, /* data block */
-       HTX_BLK_EOD    =  5, /* end-of-data block */
-       HTX_BLK_TLR    =  6, /* trailer name/value block */
-       HTX_BLK_EOT    =  7, /* end-of-trailers block */
-       HTX_BLK_EOM    =  8, /* end-of-message block */
+       HTX_BLK_TLR    =  5, /* trailer name/value block */
+       HTX_BLK_EOT    =  6, /* end-of-trailers block */
+       HTX_BLK_EOM    =  7, /* end-of-message block */
        /* 8 .. 14 unused */
        HTX_BLK_UNUSED = 15, /* unused/removed block */
 };
@@ -756,7 +755,6 @@ static inline const char *htx_blk_type_str(enum htx_blk_type type)
                case HTX_BLK_HDR:    return "HTX_BLK_HDR";
                case HTX_BLK_EOH:    return "HTX_BLK_EOH";
                case HTX_BLK_DATA:   return "HTX_BLK_DATA";
-               case HTX_BLK_EOD:    return "HTX_BLK_EOD";
                case HTX_BLK_TLR:    return "HTX_BLK_TLR";
                case HTX_BLK_EOT:    return "HTX_BLK_EOT";
                case HTX_BLK_EOM:    return "HTX_BLK_EOM";
index a6612d913400b3467f3f9f2325cbe66f44df2abd..13f87bead53f48a33af473dbb0b6462dfb62a16b 100644 (file)
@@ -245,7 +245,6 @@ comp_http_payload(struct stream *s, struct filter *filter, struct http_msg *msg,
                                blk = htx_replace_blk_value(htx, blk, v, ist2(b_head(&trash), b_data(&trash)));
                                break;
 
-                       case HTX_BLK_EOD:
                        case HTX_BLK_TLR:
                        case HTX_BLK_EOT:
                        case HTX_BLK_EOM:
index a3fd57b9157fb7b5d499b9f7f1fc6f49c4cf5317..ef796327dc59493d8cd8b7434b9c1b36bbf4a871 100644 (file)
@@ -4002,7 +4002,7 @@ static int hlua_applet_http_new(lua_State *L, struct appctx *ctx)
                        struct htx_blk *blk = htx_get_blk(htx, pos);
                        enum htx_blk_type type = htx_get_blk_type(blk);
 
-                       if (type == HTX_BLK_EOM || type == HTX_BLK_EOD)
+                       if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT)
                                break;
                        if (type == HTX_BLK_DATA)
                                len += htx_get_blksz(blk);
@@ -4251,7 +4251,6 @@ __LJMP static int hlua_applet_htx_getline_yield(lua_State *L, int status, lua_KC
                                luaL_addlstring(&appctx->b, v.ptr, vlen);
                                break;
 
-                       case HTX_BLK_EOD:
                        case HTX_BLK_TLR:
                        case HTX_BLK_EOM:
                                stop = 1;
@@ -4401,7 +4400,6 @@ __LJMP static int hlua_applet_htx_recv_yield(lua_State *L, int status, lua_KCont
                                luaL_addlstring(&appctx->b, v.ptr, vlen);
                                break;
 
-                       case HTX_BLK_EOD:
                        case HTX_BLK_TLR:
                        case HTX_BLK_EOM:
                                len = 0;
@@ -7295,7 +7293,7 @@ static void hlua_applet_htx_fct(struct appctx *ctx)
                if (!(ctx->ctx.hlua_apphttp.flags & APPLET_HDR_SENT))
                        goto error;
 
-               /* Don't add EOD and TLR because mux-h1 will take care of it */
+               /* Don't add TLR because mux-h1 will take care of it */
                if (!htx_add_endof(res_htx, HTX_BLK_EOM)) {
                        si_rx_room_blk(si);
                        goto out;
index a184f2f3ba0464781b9cef9fdb81e4349c093a60..0b8f2678f17155e840c8f60c2acd241c8db225ce 100644 (file)
@@ -848,7 +848,7 @@ static int smp_fetch_body(const struct arg *args, struct sample *smp, const char
                        struct htx_blk *blk = htx_get_blk(htx, pos);
                        enum htx_blk_type type = htx_get_blk_type(blk);
 
-                       if (type == HTX_BLK_EOM || type == HTX_BLK_EOD)
+                       if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT)
                                break;
                        if (type == HTX_BLK_DATA) {
                                if (!htx_data_to_h1(htx_get_blk_value(htx, blk), temp, 0))
@@ -919,7 +919,7 @@ static int smp_fetch_body_len(const struct arg *args, struct sample *smp, const
                        struct htx_blk *blk = htx_get_blk(htx, pos);
                        enum htx_blk_type type = htx_get_blk_type(blk);
 
-                       if (type == HTX_BLK_EOM || type == HTX_BLK_EOD)
+                       if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT)
                                break;
                        if (type == HTX_BLK_DATA)
                                len += htx_get_blksz(blk);
@@ -967,7 +967,7 @@ static int smp_fetch_body_size(const struct arg *args, struct sample *smp, const
                        struct htx_blk *blk = htx_get_blk(htx, pos);
                        enum htx_blk_type type = htx_get_blk_type(blk);
 
-                       if (type == HTX_BLK_EOM || type == HTX_BLK_EOD)
+                       if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT)
                                break;
                        if (type == HTX_BLK_DATA)
                                len += htx_get_blksz(blk);
@@ -2594,7 +2594,7 @@ static int smp_fetch_body_param(const struct arg *args, struct sample *smp, cons
                                struct htx_blk   *blk  = htx_get_blk(htx, pos);
                                enum htx_blk_type type = htx_get_blk_type(blk);
 
-                               if (type == HTX_BLK_EOM || type == HTX_BLK_EOD)
+                               if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT)
                                        break;
                                if (type == HTX_BLK_DATA) {
                                        if (!htx_data_to_h1(htx_get_blk_value(htx, blk), temp, 0))
index 2fdebd099367da5a67f436e2d30b27a5412e8f22..8be38d6f70cece88ea084fe0870bc9ee943a4725 100644 (file)
--- a/src/htx.c
+++ b/src/htx.c
@@ -482,7 +482,7 @@ struct htx_blk *htx_replace_blk_value(struct htx *htx, struct htx_blk *blk,
 }
 
 /* Transfer HTX blocks from <src> to <dst>, stopping on the first block of the
- * type <mark> (typically EOH, EOD or EOM) or when <count> bytes were moved
+ * type <mark> (typically EOH or EOM) or when <count> bytes were moved
  * (including payload and meta-data). It returns the number of bytes moved and
  * the last HTX block inserted in <dst>.
  */
@@ -781,7 +781,7 @@ struct htx_blk *htx_add_all_trailers(struct htx *htx, const struct http_hdr *hdr
        return htx_add_endof(htx, HTX_BLK_EOT);
 }
 
-/* Adds an HTX block of type EOH,EOD or EOM in <htx>. It returns the new block
+/* Adds an HTX block of type EOH or EOM in <htx>. It returns the new block
  * on success. Otherwise, it returns NULL.
  */
 struct htx_blk *htx_add_endof(struct htx *htx, enum htx_blk_type type)
index 9d6aaf23c291b39541235703901d7cdf637ac5e6..47a4071de057547f7ad1d0e5ed380ba817c65ebb 100644 (file)
@@ -1215,14 +1215,7 @@ static size_t h1_process_data(struct h1s *h1s, struct h1m *h1m, struct htx *htx,
                                ret = h1_parse_chunk_size(buf, *ofs, b_data(buf), &chksz);
                                if (ret <= 0)
                                        goto end;
-                               if (!chksz) {
-                                       if (max < sizeof(struct htx_blk) + 1 || !htx_add_endof(htx, HTX_BLK_EOD))
-                                               goto end;
-                                       h1m->state = H1_MSG_TRAILERS;
-                                       max -= sizeof(struct htx_blk) + 1;
-                               }
-                               else
-                                       h1m->state = H1_MSG_DATA;
+                               h1m->state = ((!chksz) ? H1_MSG_TRAILERS : H1_MSG_DATA);
 
                                h1m->curr_len  = chksz;
                                h1m->body_len += chksz;
@@ -1695,8 +1688,6 @@ static size_t h1_process_output(struct h1c *h1c, struct buffer *buf, size_t coun
                                        }
                                        goto done;
                                }
-                               else if (type == HTX_BLK_EOD)
-                                       break;
                                else if (type == HTX_BLK_EOT || type == HTX_BLK_TLR) {
                                        if (!chunk_memcat(tmp, "0\r\n", 3))
                                                goto copy;
index 2eb4ad411c1978c7ed42ace614cee7690b9821f9..65cefa4bd2200326678b6ed5bfc36e9d8d3e342b 100644 (file)
@@ -3734,13 +3734,12 @@ next_frame:
                goto fail;
        }
 
-       /* Trailers terminate a DATA sequence. In HTX we have to emit an EOD
-        * block, and when using chunks we must send the 0 CRLF marker. For
-        * other modes, the trailers are silently dropped.
+       /* Trailers terminate a DATA sequence. In HTX we always handle them. In
+        * legacy, when using chunks, we have to emit the 0 CRLF marker first
+        * and then handle the trailers. For other modes, the trailers are
+        * silently dropped.
         */
        if (htx) {
-               if (!htx_add_endof(htx, HTX_BLK_EOD))
-                       goto fail;
                if (h2_make_htx_trailers(list, htx) <= 0)
                        goto fail;
        }
@@ -4860,7 +4859,7 @@ static size_t h2s_htx_bck_make_req_headers(struct h2s *h2s, struct htx *htx)
  * present in <buf>, for stream <h2s>. Returns the number of bytes sent. The
  * caller must check the stream's status to detect any error which might have
  * happened subsequently to a successful send. Returns the number of data bytes
- * consumed, or zero if nothing done. Note that EOD/EOM count for 1 byte.
+ * consumed, or zero if nothing done. Note that EOM count for 1 byte.
  */
 static size_t h2s_htx_frt_make_resp_data(struct h2s *h2s, struct buffer *buf, size_t count)
 {
@@ -4883,9 +4882,9 @@ static size_t h2s_htx_frt_make_resp_data(struct h2s *h2s, struct buffer *buf, si
 
        htx = htx_from_buf(buf);
 
-       /* We only come here with HTX_BLK_DATA or HTX_BLK_EOD blocks. However,
-        * while looping, we can meet an HTX_BLK_EOM block that we'll leave to
-        * the caller to handle.
+       /* We only come here with HTX_BLK_DATA blocks. However, while looping,
+        * we can meet an HTX_BLK_EOM block that we'll leave to the caller to
+        * handle.
         */
 
  new_frame:
@@ -4894,21 +4893,11 @@ static size_t h2s_htx_frt_make_resp_data(struct h2s *h2s, struct buffer *buf, si
 
        idx   = htx_get_head(htx);
        blk   = htx_get_blk(htx, idx);
-       type  = htx_get_blk_type(blk); // DATA or EOD or EOM
+       type  = htx_get_blk_type(blk); // DATA or EOM
        bsize = htx_get_blksz(blk);
        fsize = bsize;
 
-       if (type == HTX_BLK_EOD) {
-               /* if we have an EOD, we're dealing with chunked data. We may
-                * have a set of trailers after us that the caller will want to
-                * deal with. Let's simply remove the EOD and return.
-                */
-               htx_remove_blk(htx, blk);
-               total++; // EOD counts as one byte
-               count--;
-               goto end;
-       }
-       else if (type == HTX_BLK_EOM) {
+       if (type == HTX_BLK_EOM) {
                if (h2s->flags & H2_SF_ES_SENT) {
                        /* ES already sent */
                        htx_remove_blk(htx, blk);
@@ -5542,7 +5531,6 @@ static size_t h2_snd_buf(struct conn_stream *cs, struct buffer *buf, size_t coun
                                break;
 
                        case HTX_BLK_DATA:
-                       case HTX_BLK_EOD:
                        case HTX_BLK_EOM:
                                /* all these cause the emission of a DATA frame (possibly empty).
                                 * This EOM necessarily is one before trailers, as the EOM following
index 6c510557e24a6e55339a7bb3197000b6d975a3c6..f52714b27affa1ad26681fb506a8dfd564f559b4 100644 (file)
@@ -1072,7 +1072,7 @@ int htx_wait_for_request_body(struct stream *s, struct channel *req, int an_bit)
        /* Now we're in HTTP_MSG_DATA. We just need to know if all data have
         * been received or if the buffer is full.
         */
-       if (htx_get_tail_type(htx) >= HTX_BLK_EOD ||
+       if (htx_get_tail_type(htx) > HTX_BLK_DATA ||
            channel_htx_full(req, htx, global.tune.maxrewrite))
                goto http_end;
 
index 4b994b72c330e9aa0657128df6f4a58d31fba375..d40e0890cc4e8488832f633117fc09c682a841c6 100644 (file)
@@ -2797,7 +2797,7 @@ static int stats_process_http_post(struct stream_interface *si)
                while (blk) {
                        enum htx_blk_type type = htx_get_blk_type(blk);
 
-                       if (type == HTX_BLK_EOM || type == HTX_BLK_EOD)
+                       if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT)
                                break;
                        if (type == HTX_BLK_DATA) {
                                struct ist v = htx_get_blk_value(htx, blk);
@@ -3360,7 +3360,7 @@ static void htx_stats_io_handler(struct appctx *appctx)
        }
 
        if (appctx->st0 == STAT_HTTP_DONE) {
-               /* Don't add EOD and TLR because mux-h1 will take care of it */
+               /* Don't add TLR because mux-h1 will take care of it */
                if (!htx_add_endof(res_htx, HTX_BLK_EOM)) {
                        si_rx_room_blk(si);
                        goto out;