From: Christopher Faulet Date: Tue, 15 Apr 2025 17:14:31 +0000 (+0200) Subject: MINOR: hlua/h1: Use http_parse_cont_len_header() to parse content-length value X-Git-Tag: v3.2-dev12~37 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9e05c14a416da1eb4291b604223d609ffa46ad2c;p=thirdparty%2Fhaproxy.git MINOR: hlua/h1: Use http_parse_cont_len_header() to parse content-length value 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. --- diff --git a/src/h1.c b/src/h1.c index 2a4f6ccf7..cc80d679b 100644 --- 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); diff --git a/src/hlua.c b/src/hlua.c index aedce70db..05bf3dda5 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -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 */