From: Willy Tarreau Date: Thu, 10 Sep 2026 14:05:24 +0000 (+0200) Subject: MINOR: http-htx: pass extra flags to the HTTP trailers parser X-Git-Tag: v3.5-dev7~36 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=883ba3af9068d22eb1bedf84025c9eb5c9fdc55f;p=haproxy.git MINOR: http-htx: pass extra flags to the HTTP trailers parser Let's introduce HTTP parser flags (HTTP_PF_*) and rely on them for the trailers parser. This one will need them to decide to enable upper case characters or not in header names in order to reuse it for H1 parsing. For now we only pass the direction. The current parser doesn't use it but the goal is to generalize the mechanism to other parsers in the future. --- diff --git a/include/haproxy/http-t.h b/include/haproxy/http-t.h index 837f071de..3b3d6f383 100644 --- a/include/haproxy/http-t.h +++ b/include/haproxy/http-t.h @@ -110,6 +110,10 @@ enum { HTTP_ERR_SIZE }; +/* Flags used by HTTP parsers */ +#define HTTP_PF_DIR_RES 0x00000001 /* direction: 0: request; 1: response */ + + /* HTTP parser error codes */ enum http_parser_status { HTTP_PRS_SUCCESS = 0, diff --git a/include/haproxy/http_htx.h b/include/haproxy/http_htx.h index bfe5f3622..cfb7bc5cb 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); +enum http_parser_status http_trailers_to_htx(struct http_hdr *list, 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/h3.c b/src/h3.c index 69cc9e530..b6176cd4a 100644 --- a/src/h3.c +++ b/src/h3.c @@ -1586,7 +1586,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); + prs_status = http_trailers_to_htx(list, 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 829b06c62..3cb6a816d 100644 --- a/src/http_htx.c +++ b/src/http_htx.c @@ -1996,7 +1996,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. + * is compatible with receipt of trailers. The is a union of HTTP_PF_* + * describing the parser's state and permissions (direction, pseudo-headers, + * etc). * * The trailers list must be composed of : * - n.name != NULL, n.len > 0 : literal trailer name @@ -2005,7 +2007,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) +enum http_parser_status http_trailers_to_htx(struct http_hdr *list, struct htx *htx, uint flags) { uint32_t data_ofs = htx->data; /* used to rollback on error */ enum http_parser_status ret = HTTP_PRS_SUCCESS; diff --git a/src/mux_h2.c b/src/mux_h2.c index b330f9ea4..ab8628403 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -6485,7 +6485,7 @@ next_frame: } /* Trailers terminate a DATA sequence */ - prs_status = http_trailers_to_htx(list, htx); + prs_status = http_trailers_to_htx(list, 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: