]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: hlua/h1: Use http_parse_cont_len_header() to parse content-length value
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 15 Apr 2025 17:14:31 +0000 (19:14 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 22 Apr 2025 14:14:47 +0000 (16:14 +0200)
Till now, h1_parse_cont_len_header() was used during the H1 message parsing and
by the lua HTTP applets to parse the content-length header value. But a more
generic function was added some years ago doing exactly the same operations. So
let's use it instead.

src/h1.c
src/hlua.c

index 2a4f6ccf713e11b60c9f20016bf4b8c7f58d4177..cc80d679bd88e8bade1f32e2f2261d79fca3de0d 100644 (file)
--- a/src/h1.c
+++ b/src/h1.c
@@ -1054,8 +1054,9 @@ int h1_headers_to_hdr_list(char *start, const char *stop,
                                        }
                                }
                                else if (isteqi(n, ist("content-length"))) {
-                                       ret = h1_parse_cont_len_header(h1m, &v);
+                                       unsigned long long body_len = h1m->body_len;
 
+                                       ret = http_parse_cont_len_header(&v, &body_len, (h1m->flags & H1_MF_CLEN));
                                        if (ret < 0) {
                                                state = H1_MSG_HDR_L2_LWS;
                                                ptr = v.ptr; /* Set ptr on the error */
@@ -1065,6 +1066,8 @@ int h1_headers_to_hdr_list(char *start, const char *stop,
                                                /* skip it */
                                                break;
                                        }
+                                       h1m->flags |= H1_MF_CLEN;
+                                       h1m->curr_len = h1m->body_len = body_len;
                                }
                                else if (isteqi(n, ist("connection"))) {
                                        h1_parse_connection_header(h1m, &v);
index aedce70db15f3203622a47206b544f58ac005a7f..05bf3dda533f5a5007c5c488c3716ee52597e618 100644 (file)
@@ -6282,18 +6282,21 @@ __LJMP static int hlua_applet_http_send_response(lua_State *L)
                                        goto next; /* Skip it */
                        }
                        else if (isteqi(ist2(name, nlen), ist("content-length"))) {
+                               unsigned long long body_len = h1m.body_len;
                                struct ist v = ist2(value, vlen);
                                int ret;
 
-                               ret = h1_parse_cont_len_header(&h1m, &v);
+                               ret = http_parse_cont_len_header(&v, &body_len, (h1m.flags & H1_MF_CLEN));
                                if (ret < 0) {
                                        hlua_pusherror(L, "Lua applet http '%s': Invalid '%s' header.\n",
                                                       luactx->appctx->rule->arg.hlua_rule->fcn->name,
                                                       name);
                                        WILL_LJMP(lua_error(L));
                                }
-                               else if (ret == 0)
+                               else if(ret == 0)
                                        goto next; /* Skip it */
+                               h1m.flags |= H1_MF_CLEN;
+                               h1m.curr_len = h1m.body_len = body_len;
                        }
 
                        /* Add a new header */