diff options
author | Amaury Denoyelle <adenoyelle@haproxy.com> | 2023-05-11 16:50:04 +0200 |
---|---|---|
committer | Amaury Denoyelle <adenoyelle@haproxy.com> | 2023-05-12 15:29:28 +0200 |
commit | 25cf19d5c80cc61381a18afdc3dd50428e5f8b95 (patch) | |
tree | 500e6ff6bcd6a2dfaa13065aaff4a1a04f656630 | |
parent | 76d502588d8909913dab0fb2c73cbdba8728a0b7 (diff) | |
download | haproxy-25cf19d5c80cc61381a18afdc3dd50428e5f8b95.tar.gz |
MINOR: htx: add function to set EOM reliably
Implement a new HTX utility function htx_set_eom(). If the HTX message
is empty, it will first add a dummy EOT block. This is a small trick
needed to ensure readers will detect the HTX buffer as not empty and
retrieve the EOM flag.
Replace the H2 code related by a htx_set_eom() invocation. QUIC also has
the same code which will be replaced in the next commit.
This should be backported up to 2.7 before the related QUIC patch.
-rw-r--r-- | include/haproxy/htx.h | 18 | ||||
-rw-r--r-- | src/mux_h2.c | 15 |
2 files changed, 21 insertions, 12 deletions
diff --git a/include/haproxy/htx.h b/include/haproxy/htx.h index e80ecad68..59e885a67 100644 --- a/include/haproxy/htx.h +++ b/include/haproxy/htx.h @@ -758,6 +758,24 @@ static inline int htx_expect_more(const struct htx *htx) return !(htx->flags & HTX_FL_EOM); } +/* Set EOM flag in <htx>. This function is useful if the HTX message is empty. + * In this case, an EOT block is appended first to ensure the EOM will be + * forwarded as expected. This is a workaround as it is not possibly currently + * to push an empty HTX DATA block. + * + * Returns 1 on success else 0. + */ +static inline int htx_set_eom(struct htx *htx) +{ + if (htx_is_empty(htx)) { + if (!htx_add_endof(htx, HTX_BLK_EOT)) + return 0; + } + + htx->flags |= HTX_FL_EOM; + return 1; +} + /* Copy an HTX message stored in the buffer <msg> to <htx>. We take care to * not overwrite existing data. All the message is copied or nothing. It returns * 1 on success and 0 on error. diff --git a/src/mux_h2.c b/src/mux_h2.c index 949ffb313..b531c6171 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -5095,18 +5095,9 @@ try_again: * EOM was already reported. */ if ((h2c->flags & H2_CF_IS_BACK) || !(h2s->flags & H2_SF_TUNNEL_ABRT)) { - /* If we receive an empty DATA frame with ES flag while the HTX - * message is empty, we must be sure to push a block to be sure - * the HTX EOM flag will be handled on the other side. It is a - * workaround because for now it is not possible to push empty - * HTX DATA block. And without this block, there is no way to - * "commit" the end of the message. - */ - if (htx_is_empty(htx)) { - if (!htx_add_endof(htx, HTX_BLK_EOT)) - goto fail; - } - htx->flags |= HTX_FL_EOM; + /* htx may be empty if receiving an empty DATA frame. */ + if (!htx_set_eom(htx)) + goto fail; } } |