diff --git a/src/flb_http_client.c b/src/flb_http_client.c index d17c45d6b4d..5cb434abad3 100644 --- a/src/flb_http_client.c +++ b/src/flb_http_client.c @@ -1030,7 +1030,7 @@ static void http_headers_destroy(struct flb_http_client *c) int flb_http_set_keepalive(struct flb_http_client *c) { /* check if 'keepalive' mode is enabled in the Upstream connection */ - if (flb_stream_is_keepalive(c->u_conn->stream)) { + if (flb_stream_is_keepalive(c->u_conn->stream) == FLB_FALSE) { return -1; } @@ -1149,6 +1149,9 @@ int flb_http_do(struct flb_http_client *c, size_t *bytes) size_t bytes_body = 0; char *tmp; + /* Try to add keep alive header */ + flb_http_set_keepalive(c); + /* Append pending headers */ ret = http_headers_compose(c); if (ret == -1) { diff --git a/src/flb_output.c b/src/flb_output.c index 97b26e59eb3..91e83f9868c 100644 --- a/src/flb_output.c +++ b/src/flb_output.c @@ -1310,6 +1310,10 @@ int flb_output_upstream_set(struct flb_upstream *u, struct flb_output_instance * flags |= FLB_IO_IPV6; } + if (ins->net_setup.keepalive == FLB_TRUE) { + flags |= FLB_IO_TCP_KA; + } + /* Set flags */ flb_stream_enable_flags(&u->base, flags); diff --git a/tests/internal/http_client.c b/tests/internal/http_client.c index 3013c75602b..f6d197cc611 100644 --- a/tests/internal/http_client.c +++ b/tests/internal/http_client.c @@ -34,7 +34,7 @@ struct test_ctx* test_ctx_create() return NULL; } - ret_ctx->u = flb_upstream_create(ret_ctx->config, "127.0.0.1", 80, 0, NULL); + ret_ctx->u = flb_upstream_create(ret_ctx->config, "127.0.0.1", 80, FLB_IO_TCP_KA, NULL); if (!TEST_CHECK(ret_ctx->u != NULL)) { TEST_MSG("flb_upstream_create failed"); flb_config_exit(ret_ctx->config);