add httpGet error handling

This commit is contained in:
MihailRis
2024-11-11 14:47:09 +03:00
parent d7389c2220
commit 4328c83c79
3 changed files with 36 additions and 11 deletions
+12 -3
View File
@@ -9,13 +9,18 @@
#include "util/Buffer.hpp"
namespace network {
using OnResponse = std::function<void(int, std::vector<char>)>;
using OnResponse = std::function<void(std::vector<char>)>;
using OnReject = std::function<void(const char*)>;
class Http {
public:
virtual ~Http() {}
virtual void get(const std::string& url, const OnResponse& callback) = 0;
virtual void get(
const std::string& url,
OnResponse onResponse,
OnReject onReject=nullptr
) = 0;
virtual size_t getTotalUpload() const = 0;
virtual size_t getTotalDownload() const = 0;
};
@@ -26,7 +31,11 @@ namespace network {
Network(std::unique_ptr<Http> http);
~Network();
void httpGet(const std::string& url, const OnResponse& callback);
void httpGet(
const std::string& url,
OnResponse onResponse,
OnReject onReject = nullptr
);
size_t getTotalUpload() const;
size_t getTotalDownload() const;