C++ libcurl framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cppurl/lib/cppurl.hpp

94 lines
1.9 KiB

11 months ago
#ifndef _CPPURL_
#define _CPPURL_
#include <curl/curl.h>
#include <string>
#include <string.h>
#include <map>
#include <iostream>
11 months ago
namespace marcelb {
using namespace std;
static size_t bodyCallback(void *contents, size_t size, size_t nmemb, void *body_ptr);
static size_t headerCallback(char* buffer, size_t size, size_t nitems, void* header_ptr);
enum http_version { DEFAULT, HTTP1_0, HTTP1_1, HTTP2, HTTP2TLS, HTTP2PK, HTTP3 = 30};
11 months ago
class Curl {
// input
11 months ago
CURL *curl;
CURLcode res;
struct curl_slist *headers = NULL;
string _useragent;
10 months ago
long _timeout = 0;
bool _sslverifyoff = false;
http_version _protocol_v = DEFAULT;
11 months ago
public:
// output
CURLcode curlStatus;
long httpStatus;
map<string, string> responseHeader;
string body;
/**
* Postavi zaglavlje s ključem i vrijednošću
* Novi pozivi ne brišu stara zaglavlja, ponovljena se prepišu
*/
Curl& header(const string& key, const string& value);
/**
* Postavi zaglavlja iz mape
* Ponovan poziv prepisat će ona zaglavlja koja postoje
*/
Curl& header(const map<string, string> &_headers);
/**
* Postavi u zaglavlje User-Agent
*/
Curl& useragent(const string& useragent_);
10 months ago
/**
* Postavi vrijeme isteka zahtjeva
*/
Curl& timeout(const long _timeout);
/**
* Omogući/onemogući validaciju certifikata kod SSL veza
*/
Curl& sslverifyoff();
/**
* Postavi verziju HTTP protokola
* HTTP1_0 - HTTP1_1 - HTTP2 - HTTP2TLS - HTTP2PK - HTTP3
*/
Curl& httpv(const http_version protocol_v);
/**
* Izvršiv HTTP GET zahtjev
* Vraća string HTTP tjela
*/
string get(const string& req);
/**
* Obriši spremljeno zaglavlje
*/
Curl& clearheader();
/**
* Obrši trenutnog User-Agent -a
*/
Curl& clearuseragent();
11 months ago
};
}
#endif