sync code

This commit is contained in:
Ned Wright
2025-08-08 11:10:26 +00:00
parent da20943c09
commit e4747ede14
7 changed files with 684 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
#ifndef __CURL_HTTP_CLIENT_H__
#define __CURL_HTTP_CLIENT_H__
#include <string>
#include <vector>
#include <map>
#include <curl/curl.h>
#include "messaging/http_response.h"
#include "i_http_client.h"
class CurlHttpClient : public I_HttpClient
{
public:
CurlHttpClient();
~CurlHttpClient();
void setProxy(const std::string& hosts) override;
void setBasicAuth(const std::string& username, const std::string& password) override;
void authEnabled(bool enabled) override;
HTTPResponse
get(
const std::string& url,
const std::map<std::string, std::string>& headers = {}
) override;
HTTPResponse
post(
const std::string& url,
const std::string& data,
const std::map<std::string, std::string>& headers = {}
) override;
HTTPResponse
put(
const std::string& url,
const std::string& body,
const std::map<std::string, std::string>& headers = {}
) override; HTTPResponse
patch(
const std::string& url,
const std::string& body,
const std::map<std::string, std::string>& headers = {}
) override;
HTTPResponse
del(
const std::string& url,
const std::map<std::string, std::string>& headers = {}
) override;
private:
static size_t
WriteCallback(
void *contents,
size_t size,
size_t nmemb,
std::string *userp
);
HTTPResponse
perform_request(
const std::string& method,
const std::string& url,
const std::string& body,
const std::map<std::string, std::string>& headers
);
std::string no_proxy_hosts;
bool auth_enabled;
std::string username;
std::string password;
};
#endif // __CURL_HTTP_CLIENT_H__

View File

@@ -0,0 +1,50 @@
#ifndef __I_HTTP_CLIENT_H__
#define __I_HTTP_CLIENT_H__
#include <string>
#include <map>
#include "messaging/http_response.h"
class I_HttpClient
{
public:
virtual ~I_HttpClient() = default;
virtual void setProxy(const std::string& hosts) = 0;
virtual void setBasicAuth(const std::string& username, const std::string& password) = 0;
virtual void authEnabled(bool enabled) = 0;
virtual HTTPResponse
get(
const std::string& url,
const std::map<std::string, std::string>& headers = {}
) = 0;
virtual HTTPResponse
post(
const std::string& url,
const std::string& data,
const std::map<std::string, std::string>& headers = {}
) = 0;
virtual HTTPResponse
put(
const std::string& url,
const std::string& body,
const std::map<std::string, std::string>& headers = {}
) = 0;
virtual HTTPResponse
patch(
const std::string& url,
const std::string& body,
const std::map<std::string, std::string>& headers = {}
) = 0;
virtual HTTPResponse
del(
const std::string& url,
const std::map<std::string, std::string>& headers = {}
) = 0;
};
#endif // __I_HTTP_CLIENT_H__