]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mux-h2: Use <body_len> H2S field for payload without content-length
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 18 Sep 2025 06:36:54 +0000 (08:36 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 8 Oct 2025 09:01:36 +0000 (11:01 +0200)
Before, the <body_len> H2S field was only use for verity the annonced
content-lenght value was respected. Now, this field is used for all
messages. Messages with a content-length are still handled the same way.
<body_len> is set to the content-length value and decremented by the size of
each DATA frame. For other messages, the value is initialized to ULLONG_MAX
and still decremented by the size of each DATA frame. This change is
mandatory to properly define the known input payload length value of the
sedesc.

src/mux_h2.c

index 2635056ebeb6d71a82b039f86883673b9690f582..e30ef0e3dab7cdf72aca7ffde70dcb2464096949 100644 (file)
@@ -118,7 +118,7 @@ struct h2s {
        enum h2_err errcode; /* H2 err code (H2_ERR_*) */
        enum h2_ss st;
        uint16_t status;     /* HTTP response status */
-       unsigned long long body_len; /* remaining body length according to content-length if H2_SF_DATA_CLEN */
+       unsigned long long body_len; /* remaining body length (start with content-length value if found, or ULLONG_MAX otherwise) */
        uint64_t curr_rx_ofs;  /* stream offset at which next FC-data will arrive (includes padding) */
        uint64_t last_adv_ofs; /* stream offset corresponding to last emitted WU */
        uint64_t next_max_ofs; /* max stream offset that next WU must permit (curr_rx_ofs+rx_win) */
@@ -1981,7 +1981,7 @@ static struct h2s *h2s_new(struct h2c *h2c, int id)
        h2s->errcode   = H2_ERR_NO_ERROR;
        h2s->st        = H2_SS_IDLE;
        h2s->status    = 0;
-       h2s->body_len  = 0;
+       h2s->body_len  = ULLONG_MAX;
        h2s->rx_tail   = 0;
        h2s->rx_head   = 0;
        h2s->rx_count  = 0;
@@ -3396,7 +3396,7 @@ static int h2c_handle_rst_stream(struct h2c *h2c, struct h2s *h2s)
 static struct h2s *h2c_frt_handle_headers(struct h2c *h2c, struct h2s *h2s)
 {
        struct buffer rxbuf = BUF_NULL;
-       unsigned long long body_len = 0;
+       unsigned long long body_len = ULLONG_MAX;
        uint32_t flags = 0;
        int error;
 
@@ -3617,7 +3617,7 @@ static struct h2s *h2c_frt_handle_headers(struct h2c *h2c, struct h2s *h2s)
 static struct h2s *h2c_bck_handle_headers(struct h2c *h2c, struct h2s *h2s)
 {
        struct buffer rxbuf = BUF_NULL;
-       unsigned long long body_len = 0;
+       unsigned long long body_len = ULLONG_MAX;
        uint32_t flags = 0;
        int error;
 
@@ -6323,10 +6323,10 @@ try_again:
        h2c->rcvd_c += sent;
        h2c->rcvd_s += sent;  // warning, this can also affect the closed streams!
 
-       if (h2s->flags & H2_SF_DATA_CLEN) {
-               h2s->body_len -= sent;
+       h2s->body_len -= sent;
+       if (h2s->flags & H2_SF_DATA_CLEN)
                htx->extra = h2s->body_len;
-       }
+
 
        if (sent < flen) {
                if (h2s_get_rxbuf(h2s))