From: Amaury Denoyelle Date: Wed, 28 Oct 2026 15:16:28 +0000 (+0100) Subject: MINOR: http: add to trailers parsing function X-Git-Tag: v3.5-dev12~30 X-Git-Url: https://git.kaiwu.me/%7B@url%7D?a=commitdiff_plain;h=6b3b676eb9878862c72bc19ed60068b553b678df;p=haproxy.git MINOR: http: add to trailers parsing function Adds an extra argument to http_trailers_to_htx() to specify if EOT block is necessary. Most of this times this will be set to true by callers. However, it is necessary to skip it if caller does not want to report EOM immediately after. For now, every parsers set this new argument to true. This will change for HTTP/3 parser as FIN can be received later. --- diff --git a/include/haproxy/http_htx.h b/include/haproxy/http_htx.h index cfb7bc5cb..a21d022ee 100644 --- a/include/haproxy/http_htx.h +++ b/include/haproxy/http_htx.h @@ -74,7 +74,7 @@ int http_scheme_based_normalize(struct htx *htx); void http_cookie_register(struct http_hdr *list, int idx, int *first, int *last); int http_cookie_merge(struct htx *htx, struct http_hdr *list, int first); -enum http_parser_status http_trailers_to_htx(struct http_hdr *list, struct htx *htx, uint flags); +enum http_parser_status http_trailers_to_htx(struct http_hdr *list, int need_eot, struct htx *htx, uint flags); struct buffer *http_load_errorfile(const char *file, char **errmsg); struct buffer *http_load_errormsg(const char *key, const struct ist msg, char **errmsg); diff --git a/src/h1_htx.c b/src/h1_htx.c index ae848a54f..f0c0237d1 100644 --- a/src/h1_htx.c +++ b/src/h1_htx.c @@ -1065,7 +1065,7 @@ int h1_parse_msg_tlrs(struct h1m *h1m, struct htx *dsthtx, parser_flags = HTTP_PF_UPCASE_OK; parser_flags |= (h1m->flags & H1_MF_RESP) ? HTTP_PF_DIR_RES : 0; - if (http_trailers_to_htx(hdrs, dsthtx, parser_flags) != HTTP_PRS_SUCCESS) + if (http_trailers_to_htx(hdrs, 1, dsthtx, parser_flags) != HTTP_PRS_SUCCESS) goto error; h1m->state = H1_MSG_DONE; diff --git a/src/h3.c b/src/h3.c index 167ce9d9b..33fb55b07 100644 --- a/src/h3.c +++ b/src/h3.c @@ -1634,7 +1634,7 @@ static ssize_t h3_trailers_to_htx(struct qcs *qcs, const struct buffer *buf, goto out; } - prs_status = http_trailers_to_htx(list, htx, (qcs->qcc->flags & QC_CF_IS_BACK) ? HTTP_PF_DIR_RES : 0); + prs_status = http_trailers_to_htx(list, 1, htx, (qcs->qcc->flags & QC_CF_IS_BACK) ? HTTP_PF_DIR_RES : 0); switch (prs_status) { case HTTP_PRS_SUCCESS: break; diff --git a/src/http_htx.c b/src/http_htx.c index 518536559..23a8da263 100644 --- a/src/http_htx.c +++ b/src/http_htx.c @@ -1978,7 +1978,9 @@ int http_cookie_merge(struct htx *htx, struct http_hdr *list, int first) * , and an HTTP_PRS_SUCCESS status code is returned if some bytes were * emitted. In case of error, another code is returned, indicating the nature * of the problem. The caller must have verified that the message in the buffer - * is compatible with receipt of trailers. The is a union of HTTP_PF_* + * is compatible with receipt of trailers. If is true, the EOT + * block is appended to the HTX message. Caller may want to skip it for now if + * EOM reporting needs to be delayed. The is a union of HTTP_PF_* * describing the parser's state and permissions (direction, pseudo-headers, * etc). * @@ -1989,7 +1991,7 @@ int http_cookie_merge(struct htx *htx, struct http_hdr *list, int first) * - in all cases except the end of list, v.name and v.len must designate a * valid value. */ -enum http_parser_status http_trailers_to_htx(struct http_hdr *list, struct htx *htx, uint flags) +enum http_parser_status http_trailers_to_htx(struct http_hdr *list, int need_eot, struct htx *htx, uint flags) { uint32_t data_ofs = htx->data; /* used to rollback on error */ enum http_parser_status ret = HTTP_PRS_SUCCESS; @@ -2121,7 +2123,7 @@ enum http_parser_status http_trailers_to_htx(struct http_hdr *list, struct htx * } /* now finalize the trailers block */ - if (!htx_add_endof(htx, HTX_BLK_EOT)) { + if (need_eot && !htx_add_endof(htx, HTX_BLK_EOT)) { ret = HTTP_PRS_TOO_LARGE; goto fail; } diff --git a/src/mux_h2.c b/src/mux_h2.c index 1bab63c2a..39fd6cfb4 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -6605,7 +6605,7 @@ next_frame: } /* Trailers terminate a DATA sequence */ - prs_status = http_trailers_to_htx(list, htx, (h2c->flags & H2_CF_IS_BACK) ? HTTP_PF_DIR_RES : 0); + prs_status = http_trailers_to_htx(list, 1, htx, (h2c->flags & H2_CF_IS_BACK) ? HTTP_PF_DIR_RES : 0); if (prs_status != HTTP_PRS_SUCCESS) { switch (prs_status) { case HTTP_PRS_INV_HNAME: