fix(userspace/engine,userspace/falco): set http output contenttype to text/plain when json output is disabled

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>

Co-authored-by: Leonardo Grasso <me@leonardograsso.com>
This commit is contained in:
Federico Di Pierro 2022-01-10 09:40:40 +01:00 committed by poiana
parent eaccfbe82d
commit 475ed0dbeb
3 changed files with 10 additions and 3 deletions

View File

@ -135,7 +135,7 @@ void falco_outputs::add_output(falco::outputs::config oc)
throw falco_exception("Output not supported: " + oc.name);
}
oo->init(oc, m_buffered, m_hostname);
oo->init(oc, m_buffered, m_hostname, m_json_output);
m_outputs.push_back(oo);
}

View File

@ -63,11 +63,12 @@ class abstract_output
public:
virtual ~abstract_output() {}
void init(config oc, bool buffered, std::string hostname)
void init(config oc, bool buffered, std::string hostname, bool json_output)
{
m_oc = oc;
m_buffered = buffered;
m_hostname = hostname;
m_json_output = json_output;
}
// Return the output's name as per its configuration.
@ -89,6 +90,7 @@ protected:
config m_oc;
bool m_buffered;
std::string m_hostname;
bool m_json_output;
};
} // namespace outputs

View File

@ -27,8 +27,13 @@ void falco::outputs::output_http::output(const message *msg)
curl = curl_easy_init();
if(curl)
{
if (m_json_output)
{
slist1 = curl_slist_append(slist1, "Content-Type: application/json");
} else {
slist1 = curl_slist_append(slist1, "Content-Type: text/plain");
}
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist1);
curl_easy_setopt(curl, CURLOPT_URL, m_oc.options["url"].c_str());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, msg->msg.c_str());