]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: http-htx: pass extra flags to the HTTP trailers parser
authorWilly Tarreau <w@1wt.eu>
Thu, 10 Sep 2026 14:05:24 +0000 (16:05 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 11 Sep 2026 08:08:12 +0000 (10:08 +0200)
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.

include/haproxy/http-t.h
include/haproxy/http_htx.h
src/h3.c
src/http_htx.c
src/mux_h2.c

index 837f071de5a81c27e80a95fa1df7315787eaee28..3b3d6f383b1b7495010e545a9c7e7a0a76cf5f18 100644 (file)
@@ -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,
index bfe5f362209e5525aefa1f5d3a568fb2ef77165e..cfb7bc5cb1d4fe94e5d51e8bb501de3ad7346ec4 100644 (file)
@@ -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);
index 69cc9e530a4416e3dd8e666c318e5e6bb3c93284..b6176cd4a116dcfe88945fe66869a65a0ccba15a 100644 (file)
--- 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;
index 829b06c627c173b603fb5053602087b13a9b3ca1..3cb6a816d83b643b8894e558cdb0f6de3b5be42e 100644 (file)
@@ -1996,7 +1996,9 @@ int http_cookie_merge(struct htx *htx, struct http_hdr *list, int first)
  * <htx>, 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 <flags> is a union of HTTP_PF_*
+ * describing the parser's state and permissions (direction, pseudo-headers,
+ * etc).
  *
  * The trailers list <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;
index b330f9ea4b2ad5648ccfdc890d9e5d29ee42cc2e..ab86284036562430f98368018750878a8d66882e 100644 (file)
@@ -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: