47 lines
1.1 KiB
C++
47 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include <openssl/err.h>
|
|
#include <openssl/ssl.h>
|
|
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <map>
|
|
|
|
|
|
class HttpClient {
|
|
// TODO at this moment only https is implemented
|
|
|
|
private:
|
|
SSL *ssl;
|
|
int sock;
|
|
|
|
std::string full_url, proto, server, port, uri, params, href;
|
|
std::basic_string<char> ssl_read_packet;
|
|
std::map<std::string, std::string> headers_map;
|
|
|
|
public:
|
|
HttpClient() = default;
|
|
|
|
std::pair<int, std::string> doRequest(const std::string &method, const std::string &url, const std::map<std::string, std::string> &headers, const std::string &request_body);
|
|
|
|
private:
|
|
static std::string inetAddress(const std::string &hostname);
|
|
|
|
int sslRecvPacket();
|
|
|
|
int sslSendPacket(const std::string &buf);
|
|
|
|
int sslRequest(const std::string &server_name, const std::string &request);
|
|
|
|
static void logSSL();
|
|
static void showCerts(SSL* ssl);
|
|
|
|
void parseURL(const std::string &url);
|
|
|
|
[[nodiscard]] static std::string createRequestHeaders(const std::map<std::string, std::string> &headers) ;
|
|
|
|
int responseStatusCode(const std::string &status_str) const;
|
|
|
|
void responseHeaders(const std::string &hdr);
|
|
};
|