Adds support to https audit log output

This functionality was built for test only.
This commit is contained in:
Felipe Zimmerle
2016-04-02 14:44:46 -03:00
parent e5acc95de8
commit 8d052853a8
9 changed files with 165 additions and 2 deletions

View File

@@ -50,6 +50,15 @@ void HttpsClient::setKey(const std::string& key) {
m_key = "ModSec-key: " + key;
}
void HttpsClient::setRequestBody(const std::string& requestBody) {
m_requestBody = requestBody;
}
void HttpsClient::setRequestType(const std::string& requestType) {
m_requestType = requestType;
}
#ifdef MSC_WITH_CURL
bool HttpsClient::download(const std::string &uri) {
CURL *curl;
@@ -68,6 +77,12 @@ bool HttpsClient::download(const std::string &uri) {
headers_chunk = curl_slist_append(headers_chunk, uniqueId.c_str());
headers_chunk = curl_slist_append(headers_chunk, status.c_str());
if (m_requestType.empty() == false) {
std::string hdr = "Content-Type: " + m_requestType;
headers_chunk = curl_slist_append(headers_chunk, hdr.c_str());
}
if (m_key.empty() == false) {
headers_chunk = curl_slist_append(headers_chunk, m_key.c_str());
}
@@ -91,6 +106,10 @@ bool HttpsClient::download(const std::string &uri) {
/* We want Curl to return error in case there is an HTTP error code */
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
if (m_requestBody.empty() == false) {
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, m_requestBody.c_str());
}
res = curl_easy_perform(curl);
curl_slist_free_all(headers_chunk);

View File

@@ -36,7 +36,9 @@ class HttpsClient {
HttpsClient()
: content(""),
error(""),
m_key("") { }
m_key(""),
m_requestBody(""),
m_requestType("") { }
bool download(const std::string &uri);
std::string content;
@@ -44,10 +46,14 @@ class HttpsClient {
static size_t handle(char * data, size_t size, size_t nmemb, void * p);
size_t handle_impl(char * data, size_t size, size_t nmemb);
void setKey(const std::string& key);
void setRequestType(const std::string& requestType);
void setRequestBody(const std::string& requestType);
std::string error;
private:
std::string m_key;
std::string m_requestBody;
std::string m_requestType;
};