From 91379f79f858f0ab7bfa28225ca4d6c6e8e1b150 Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Mon, 14 Feb 2022 17:14:59 +0100 Subject: [PATCH] MINOR: h3: implement DATA parsing Add a new function h3_data_to_htx. This function is used to parse a H3 DATA frame and copy it in the mux stream HTX buffer. This is required to support HTTP POST data. Note that partial transfers if the HTX buffer is fulled is not properly handle. This causes large DATA transfer to fail at the moment. --- src/h3.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/h3.c b/src/h3.c index 883222985..48bb8cf3e 100644 --- a/src/h3.c +++ b/src/h3.c @@ -189,6 +189,38 @@ static int h3_headers_to_htx(struct qcs *qcs, struct buffer *buf, uint64_t len, return 0; } +/* Copy from buffer a H3 DATA frame of length in QUIC stream + * HTX buffer. must be set if this is the last data to transfer from this + * stream. + * + * Returns 0 on success else non-zero + */ +static int h3_data_to_htx(struct qcs *qcs, struct buffer *buf, uint64_t len, + char fin) +{ + struct buffer *appbuf; + struct htx *htx = NULL; + size_t htx_sent; + int htx_space; + + appbuf = qc_get_buf(qcs, &qcs->rx.app_buf); + BUG_ON(!appbuf); + htx = htx_from_buf(appbuf); + + htx_space = htx_free_data_space(htx); + BUG_ON(!htx_space || htx_space < len); + + htx_sent = htx_add_data(htx, ist2(b_head(buf), len)); + /* TODO handle full appbuf */ + BUG_ON(htx_sent < len); + + if (fin) + htx->flags |= HTX_FL_EOM; + htx_to_buf(htx, appbuf); + + return 0; +} + /* Decode remotely initiated bidi-stream. must be set to indicate * that we received the last data of the stream. * Returns <0 on error else 0. @@ -226,6 +258,7 @@ static int h3_decode_qcs(struct qcs *qcs, int fin, void *ctx) switch (ftype) { case H3_FT_DATA: + h3_data_to_htx(qcs, rxbuf, flen, last_stream_frame); break; case H3_FT_HEADERS: h3_headers_to_htx(qcs, rxbuf, flen, last_stream_frame);