diff --git a/loader/src/loader/updater.cpp b/loader/src/loader/updater.cpp index 3e89713f..b5d078c2 100644 --- a/loader/src/loader/updater.cpp +++ b/loader/src/loader/updater.cpp @@ -280,6 +280,7 @@ void updater::downloadLoaderUpdate(std::string const& url) { LoaderUpdateEvent(UpdateFinished()).post(); }) .expect([](std::string const& info) { + log::error("Failed to download latest update {}", info); LoaderUpdateEvent( UpdateFailed("Unable to download update: " + info) ).post(); @@ -334,6 +335,7 @@ void updater::checkForLoaderUpdates() { ).post(); }, [](std::string const& info) { + log::error("Failed to fetch updates {}", info); LoaderUpdateEvent( UpdateFailed("Unable to check for updates: " + info) ).post(); diff --git a/loader/src/utils/web.cpp b/loader/src/utils/web.cpp index cfa49ae5..b708a19e 100644 --- a/loader/src/utils/web.cpp +++ b/loader/src/utils/web.cpp @@ -336,21 +336,19 @@ SentAsyncWebRequest::Impl::Impl(SentAsyncWebRequest* self, AsyncWebRequest const curl_easy_setopt(curl, CURLOPT_HEADERDATA, &data); curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, +[](char* buffer, size_t size, size_t nitems, void* ptr){ auto data = static_cast(ptr); - std::string header; - header.append(buffer, size * nitems); - // send the header to the response header callback - Loader::get()->queueInMainThread([self = data->self, header]() { - std::unordered_map headers; - std::string line; - std::stringstream ss(header); - while (std::getline(ss, line)) { - auto colon = line.find(':'); - if (colon == std::string::npos) continue; - auto key = line.substr(0, colon); - auto value = line.substr(colon + 2); - self->m_responseHeader[key] = value; + std::unordered_map headers; + std::string line; + std::stringstream ss(std::string(buffer, size * nitems)); + while (std::getline(ss, line)) { + auto colon = line.find(':'); + if (colon == std::string::npos) continue; + auto key = line.substr(0, colon); + auto value = line.substr(colon + 2); + if (value.ends_with('\r')) { + value = value.substr(0, value.size() - 1); } - }); + data->self->m_responseHeader[key] = value; + } return size * nitems; }); @@ -572,7 +570,12 @@ AsyncWebRequest& AsyncWebRequest::timeout(std::chrono::seconds seconds) { } AsyncWebRequest& AsyncWebRequest::header(std::string_view const header) { - m_impl->m_httpHeaders.push_back(std::string(header)); + std::string str(header); + // remove \r and \n + str.erase(std::remove_if(str.begin(), str.end(), [](char c) { + return c == '\r' || c == '\n'; + }), str.end()); + m_impl->m_httpHeaders.push_back(str); return *this; }