2023-10-04 12:00:32 +02:00
|
|
|
#if defined(OS_WEB)
|
|
|
|
|
|
|
|
#include <hex/helpers/http_requests.hpp>
|
|
|
|
|
|
|
|
namespace hex {
|
|
|
|
|
|
|
|
HttpRequest::HttpRequest(std::string method, std::string url) : m_method(std::move(method)), m_url(std::move(url)) {
|
2023-12-19 13:10:25 +01:00
|
|
|
emscripten_fetch_attr_init(&m_attr);
|
2023-10-04 12:00:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HttpRequest::HttpRequest(HttpRequest &&other) noexcept {
|
2023-12-19 13:10:25 +01:00
|
|
|
m_attr = other.m_attr;
|
2023-10-04 12:00:32 +02:00
|
|
|
|
2023-12-19 13:10:25 +01:00
|
|
|
m_method = std::move(other.m_method);
|
|
|
|
m_url = std::move(other.m_url);
|
|
|
|
m_headers = std::move(other.m_headers);
|
|
|
|
m_body = std::move(other.m_body);
|
2023-10-04 12:00:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HttpRequest& HttpRequest::operator=(HttpRequest &&other) noexcept {
|
2023-12-19 13:10:25 +01:00
|
|
|
m_attr = other.m_attr;
|
2023-10-04 12:00:32 +02:00
|
|
|
|
2023-12-19 13:10:25 +01:00
|
|
|
m_method = std::move(other.m_method);
|
|
|
|
m_url = std::move(other.m_url);
|
|
|
|
m_headers = std::move(other.m_headers);
|
|
|
|
m_body = std::move(other.m_body);
|
2023-10-04 12:00:32 +02:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
HttpRequest::~HttpRequest() { }
|
|
|
|
|
|
|
|
void HttpRequest::setDefaultConfig() { }
|
|
|
|
|
|
|
|
std::future<HttpRequest::Result<std::vector<u8>>> HttpRequest::downloadFile() {
|
|
|
|
return std::async(std::launch::async, [this] {
|
|
|
|
std::vector<u8> response;
|
|
|
|
|
|
|
|
return this->executeImpl<std::vector<u8>>(response);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-11-10 21:59:20 +01:00
|
|
|
void HttpRequest::setProxyUrl(std::string proxy) {
|
2023-10-04 12:00:32 +02:00
|
|
|
hex::unused(proxy);
|
|
|
|
}
|
|
|
|
|
2023-11-10 21:59:20 +01:00
|
|
|
void HttpRequest::setProxyState(bool state) {
|
|
|
|
hex::unused(state);
|
|
|
|
}
|
|
|
|
|
2023-10-04 12:00:32 +02:00
|
|
|
void HttpRequest::checkProxyErrors() { }
|
|
|
|
|
|
|
|
int HttpRequest::progressCallback(void *contents, curl_off_t dlTotal, curl_off_t dlNow, curl_off_t ulTotal, curl_off_t ulNow) {
|
|
|
|
hex::unused(contents, dlTotal, dlNow, ulTotal, ulNow);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|