add Http::fetch(...) methods

This commit is contained in:
2022-11-18 16:38:03 +01:00
parent 2bd56c87e4
commit 89249f1297
2 changed files with 132 additions and 57 deletions

View File

@@ -54,6 +54,14 @@ public:
static const long HTTP_STATUS_301_Moved_Permanently = 301;
static const long HTTP_STATUS_302_Found = 302;
enum Method {
method_get,
method_post,
method_put,
method_patch,
method_delete,
method_options,
};
Http();
~Http();
@@ -157,6 +165,14 @@ public:
*/
void verify_ssl(bool verify);
/*
* in can be a null pointer
* in such a case a body payload is not sent
*/
bool fetch(Method method, const wchar_t * url, const std::string * in, pt::WTextStream & out, bool clear_stream = true);
bool fetch(Method method, const std::wstring & url, const std::string * in, pt::WTextStream & out, bool clear_stream = true);
bool fetch(Method method, const wchar_t * url, pt::WTextStream * in, pt::WTextStream & out, bool clear_stream = true);
bool get(const wchar_t * url, std::wstring & out, bool clear_str = true);
bool get(const std::wstring & url, std::wstring & out, bool clear_str = true);
bool get(const pt::WTextStream & url, std::wstring & out, bool clear_str = true);
@@ -178,6 +194,7 @@ public:
*/
long get_status();
static const wchar_t * method_to_str(Method method);
private:
@@ -200,7 +217,6 @@ private:
pt::Space * debug_info;
bool follow_location;
bool verify_ssl_cert;
bool use_post_method; /* if false then use put method - used only when calling post() or put() methods */
std::wstring temp_header;
std::string temp_header_ascii;
@@ -208,8 +224,8 @@ private:
std::wstring temp_header_value;
std::string temp_header_value_ascii;
bool post_put(const wchar_t * url, const std::string & in, pt::WTextStream & out, bool clear_stream);
bool fetch_internal(const char * url, const std::string * in, pt::TextStream & out);
bool fetch_internal(Method method, const char * url, const std::string * in, pt::TextStream & out);
void put_method(Method & method);
static size_t fetch_read_function(char * ptr, size_t size, size_t nmemb, void * userdata);
static int fetch_seek_set(Http * http, curl_off_t offset);
static int fetch_seek_cur(Http * http, curl_off_t offset);