From: Christopher Faulet Date: Tue, 4 Jun 2019 08:08:28 +0000 (+0200) Subject: MINOR: htx: Don't use end-of-data blocks anymore X-Git-Tag: v2.0-dev6~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=54b5e214b0c07bcee0812dbb0dcc02cf89586d48;p=thirdparty%2Fhaproxy.git MINOR: htx: Don't use end-of-data blocks anymore 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. --- diff --git a/contrib/prometheus-exporter/service-prometheus.c b/contrib/prometheus-exporter/service-prometheus.c index 483e7031f1..c55233727b 100644 --- a/contrib/prometheus-exporter/service-prometheus.c +++ b/contrib/prometheus-exporter/service-prometheus.c @@ -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; diff --git a/include/common/htx.h b/include/common/htx.h index e2d4e15a11..cb998b99e6 100644 --- a/include/common/htx.h +++ b/include/common/htx.h @@ -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"; diff --git a/src/flt_http_comp.c b/src/flt_http_comp.c index a6612d9134..13f87bead5 100644 --- a/src/flt_http_comp.c +++ b/src/flt_http_comp.c @@ -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: diff --git a/src/hlua.c b/src/hlua.c index a3fd57b915..ef796327dc 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -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; diff --git a/src/http_fetch.c b/src/http_fetch.c index a184f2f3ba..0b8f2678f1 100644 --- a/src/http_fetch.c +++ b/src/http_fetch.c @@ -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)) diff --git a/src/htx.c b/src/htx.c index 2fdebd0993..8be38d6f70 100644 --- 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 to , stopping on the first block of the - * type (typically EOH, EOD or EOM) or when bytes were moved + * type (typically EOH or EOM) or when bytes were moved * (including payload and meta-data). It returns the number of bytes moved and * the last HTX block inserted in . */ @@ -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 . It returns the new block +/* Adds an HTX block of type EOH or EOM in . 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) diff --git a/src/mux_h1.c b/src/mux_h1.c index 9d6aaf23c2..47a4071de0 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -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; diff --git a/src/mux_h2.c b/src/mux_h2.c index 2eb4ad411c..65cefa4bd2 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -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 , for stream . 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 diff --git a/src/proto_htx.c b/src/proto_htx.c index 6c510557e2..f52714b27a 100644 --- a/src/proto_htx.c +++ b/src/proto_htx.c @@ -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; diff --git a/src/stats.c b/src/stats.c index 4b994b72c3..d40e0890cc 100644 --- a/src/stats.c +++ b/src/stats.c @@ -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;