From d99c137b0948dee8d123ada2aa268f1631389571 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Sat, 16 Dec 2023 05:35:00 -0800 Subject: [PATCH] feat(outputs_http): implement keep alive Signed-off-by: Samuel Gaist --- falco.yaml | 1 + userspace/falco/configuration.cpp | 4 ++++ userspace/falco/outputs_http.cpp | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/falco.yaml b/falco.yaml index cc7123f1ea6..205d182429c 100644 --- a/falco.yaml +++ b/falco.yaml @@ -567,6 +567,7 @@ http_output: # Whether to echo server answers to stdout echo: false compress_uploads: false + keep_alive: false # [Stable] `program_output` # diff --git a/userspace/falco/configuration.cpp b/userspace/falco/configuration.cpp index 7292ef2f60e..4ffc1ebdce1 100644 --- a/userspace/falco/configuration.cpp +++ b/userspace/falco/configuration.cpp @@ -313,6 +313,10 @@ void falco_configuration::load_yaml(const std::string& config_name, const yaml_h compress_uploads = config.get_scalar("http_output.compress_uploads", false); http_output.options["compress_uploads"] = compress_uploads? std::string("true") : std::string("false"); + bool keep_alive; + keep_alive = config.get_scalar("http_output.keep_alive", false); + http_output.options["keep_alive"] = keep_alive? std::string("true") : std::string("false"); + m_outputs.push_back(http_output); } diff --git a/userspace/falco/outputs_http.cpp b/userspace/falco/outputs_http.cpp index 7c5b3150079..44c94c34ba3 100644 --- a/userspace/falco/outputs_http.cpp +++ b/userspace/falco/outputs_http.cpp @@ -102,6 +102,11 @@ bool falco::outputs::output_http::init(const config& oc, bool buffered, const st CHECK_RES(curl_easy_setopt(m_curl, CURLOPT_TRANSFER_ENCODING, 1L)); } + if(m_oc.options["keep_alive"] == std::string("true")) + { + CHECK_RES(curl_easy_setopt(m_curl, CURLOPT_TCP_KEEPALIVE, 1L)); + } + if(res != CURLE_OK) { err = "libcurl error: " + std::string(curl_easy_strerror(res));