From 3fae365c2d74f020ad382cd2c992c40c6d21b943 Mon Sep 17 00:00:00 2001 From: Srinivas Chippagiri Date: Sun, 15 Nov 2026 00:04:16 -0800 Subject: [PATCH 1/5] http_server: handle pipelined HTTP/1.1 requests already in the buffer An HTTP/1.x session parses one request per read event. When a client pipelines requests, the next one is moved to the front of incoming_data after the first is handled, but nothing parses it until more data arrives, so the client waits up to the keep-alive timeout for an answer. After the queued requests are dispatched, parse the leftover bytes and dispatch again while complete requests remain and the connection stays open. Signed-off-by: Srinivas Chippagiri --- src/http_server/flb_http_server.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/http_server/flb_http_server.c b/src/http_server/flb_http_server.c index f13b8e3c968..c1b434410e3 100644 --- a/src/http_server/flb_http_server.c +++ b/src/http_server/flb_http_server.c @@ -544,6 +544,7 @@ static int flb_http_server_client_activity_event_handler(void *data) close_connection = FLB_FALSE; +dispatch_requests: cfl_list_foreach_safe(iterator, backup_iterator, &session->request_queue) { @@ -602,6 +603,31 @@ static int flb_http_server_client_activity_event_handler(void *data) } } + /* + * An HTTP/1.x session parses one request at a time, and the bytes of a + * pipelined request that arrived in the same read stay in incoming_data. + * No read event will come for them, so parse them now instead of + * leaving the client waiting until it sends more data. + */ + if (!close_connection && + session->version != HTTP_PROTOCOL_VERSION_AUTODETECT && + session->version <= HTTP_PROTOCOL_VERSION_11 && + cfl_sds_len(session->incoming_data) > 0) { + result = flb_http1_server_session_ingest(&session->http1, NULL, 0); + + if (result < 0) { + /* Send the responses of the requests already handled */ + flb_http_server_session_write(session); + flb_http_server_session_destroy(session); + + return -1; + } + + if (!cfl_list_is_empty(&session->request_queue)) { + goto dispatch_requests; + } + } + result = flb_http_server_session_write(session); if (result != 0) { From 4755c91525dbc6a2a658ac44ad5cb05cf51ca028 Mon Sep 17 00:00:00 2001 From: Srinivas Chippagiri Date: Sun, 15 Nov 2026 00:04:17 -0800 Subject: [PATCH 2/5] tests: integration: cover pipelined HTTP/1.1 requests in in_http Signed-off-by: Srinivas Chippagiri --- .../in_http/tests/test_http1_pipelining.py | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 tests/integration/scenarios/in_http/tests/test_http1_pipelining.py diff --git a/tests/integration/scenarios/in_http/tests/test_http1_pipelining.py b/tests/integration/scenarios/in_http/tests/test_http1_pipelining.py new file mode 100644 index 00000000000..af4d534439c --- /dev/null +++ b/tests/integration/scenarios/in_http/tests/test_http1_pipelining.py @@ -0,0 +1,81 @@ +"""Pipelined HTTP/1.1 requests sent in a single write are all answered.""" + +import socket + +import pytest + +from utils.test_service import FluentBitTestService + + +@pytest.fixture +def listener(tmp_path): + config = tmp_path / "http1_pipelining.yaml" + config.write_text("""service: + flush: 1 + grace: 1 + http_server: on + http_port: ${FLUENT_BIT_HTTP_MONITORING_PORT} +pipeline: + inputs: + - name: http + listen: 127.0.0.1 + port: ${FLUENT_BIT_TEST_LISTENER_PORT} + enable_health_endpoint: on + outputs: + - name: null + match: '*' +""") + service = FluentBitTestService(str(config)) + service.start() + try: + yield service.flb_listener_port + finally: + service.stop() + + +def read_response(stream): + """Read one response from a buffered socket file, return its status.""" + status_line = stream.readline() + assert status_line, "connection closed before a response arrived" + status = int(status_line.split()[1]) + + length = 0 + chunked = False + while True: + line = stream.readline() + if line in (b"\r\n", b"\n", b""): + break + name, _, value = line.decode("latin-1").partition(":") + if name.strip().lower() == "content-length": + length = int(value.strip()) + elif name.strip().lower() == "transfer-encoding" and "chunked" in value.lower(): + chunked = True + + if chunked: + while True: + size = int(stream.readline().split(b";")[0], 16) + stream.read(size + 2) + if size == 0: + break + else: + stream.read(length) + + return status + + +def test_http1_pipelined_requests_in_one_write(listener): + # A chunked body has an exact end. With Content-Length the body currently + # runs to the end of the buffer (#12652), which is a separate bug. + body = b'{"a":1}' + first = (b"POST /one HTTP/1.1\r\nHost: localhost\r\nContent-Type: application/json\r\n" + b"Transfer-Encoding: chunked\r\n\r\n" + + f"{len(body):x}\r\n".encode() + body + b"\r\n0\r\n\r\n") + second = b"GET /health HTTP/1.1\r\nHost: localhost\r\n\r\n" + + with socket.create_connection(("127.0.0.1", listener), timeout=5) as sock: + # Both requests in one write, and nothing sent after them: the second + # one must be answered without waiting for more data from the client. + sock.sendall(first + second) + stream = sock.makefile("rb") + assert read_response(stream) == 201 + assert read_response(stream) == 200 From 3be7a890964c3ddeeb42bba3991e27994a70f354 Mon Sep 17 00:00:00 2001 From: Srinivas Chippagiri Date: Sun, 15 Nov 2026 02:21:08 -0800 Subject: [PATCH 3/5] http_server: keep pipelined data after a request without a body Signed-off-by: Srinivas Chippagiri --- src/http_server/flb_http_server_http1.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/http_server/flb_http_server_http1.c b/src/http_server/flb_http_server_http1.c index 26d592627b0..dc03361c781 100644 --- a/src/http_server/flb_http_server_http1.c +++ b/src/http_server/flb_http_server_http1.c @@ -72,9 +72,21 @@ static int http1_evict_request(struct flb_http1_server_session *session) session_buffer_length = cfl_sds_len(session_buffer); - request_length = mk_http_parser_request_size(&session->inner_parser, - session_buffer, - session_buffer_length); + if (!mk_http_parser_is_content_chunked(&session->inner_parser) && + session->inner_parser.header_content_length <= 0 && + session->inner_parser.i >= 0) { + /* + * A request without a body, such as a GET, ends at the blank line + * after its headers, and the parser stops on that final LF. Keep + * whatever follows it, which is the next pipelined request. + */ + request_length = (size_t) session->inner_parser.i + 1; + } + else { + request_length = mk_http_parser_request_size(&session->inner_parser, + session_buffer, + session_buffer_length); + } if (request_length == -1 || request_length > session_buffer_length) { From cb417e6d31c540d5e2a00fdfbe56a64005a6bdd1 Mon Sep 17 00:00:00 2001 From: Srinivas Chippagiri Date: Sun, 15 Nov 2026 02:21:08 -0800 Subject: [PATCH 4/5] tests: integration: cover pipelined requests without a body in in_http Signed-off-by: Srinivas Chippagiri --- .../scenarios/in_http/tests/test_http1_pipelining.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/integration/scenarios/in_http/tests/test_http1_pipelining.py b/tests/integration/scenarios/in_http/tests/test_http1_pipelining.py index af4d534439c..944a85b8e85 100644 --- a/tests/integration/scenarios/in_http/tests/test_http1_pipelining.py +++ b/tests/integration/scenarios/in_http/tests/test_http1_pipelining.py @@ -79,3 +79,15 @@ def test_http1_pipelined_requests_in_one_write(listener): stream = sock.makefile("rb") assert read_response(stream) == 201 assert read_response(stream) == 200 + + +def test_http1_pipelined_header_only_requests(listener): + # Two requests without a body. The first one ends at its blank line, so + # the second one has to be kept in the buffer when the first is evicted. + request = b"GET /health HTTP/1.1\r\nHost: localhost\r\n\r\n" + + with socket.create_connection(("127.0.0.1", listener), timeout=5) as sock: + sock.sendall(request + request) + stream = sock.makefile("rb") + assert read_response(stream) == 200 + assert read_response(stream) == 200 From 86825ad9d5aad46b46fed7a555e9dc68e2c795c8 Mon Sep 17 00:00:00 2001 From: Srinivas Chippagiri Date: Mon, 16 Nov 2026 13:45:43 -0800 Subject: [PATCH 5/5] http_server: shrink the buffer when a pipelined request is evicted Signed-off-by: Srinivas Chippagiri --- src/http_server/flb_http_server_http1.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/http_server/flb_http_server_http1.c b/src/http_server/flb_http_server_http1.c index dc03361c781..2896bbb501b 100644 --- a/src/http_server/flb_http_server_http1.c +++ b/src/http_server/flb_http_server_http1.c @@ -103,6 +103,7 @@ static int http1_evict_request(struct flb_http1_server_session *session) session_buffer_length); session_buffer[session_buffer_length] = '\0'; + cfl_sds_set_len(session_buffer, session_buffer_length); } else { cfl_sds_set_len(session_buffer, 0);