Fix AsyncWebRequest backwards compat

This commit is contained in:
altalk23 2023-09-08 18:02:59 +03:00
parent 1718e815d2
commit 83e48fa8dc
2 changed files with 11 additions and 11 deletions

View file

@ -106,12 +106,12 @@ namespace geode::utils::web {
// Hack until 2.0.0 to store extra members in AsyncWebRequest // Hack until 2.0.0 to store extra members in AsyncWebRequest
struct AsyncWebRequestData { struct AsyncWebRequestData {
std::variant<std::monostate, std::ostream*, ghc::filesystem::path> m_target;
std::string m_userAgent; std::string m_userAgent;
std::string m_customRequest; std::string m_customRequest;
bool m_isPostRequest = false; bool m_isPostRequest = false;
std::string m_postFields; std::string m_postFields;
bool m_isJsonRequest = false; bool m_isJsonRequest = false;
bool m_sent = false;
}; };
/** /**
@ -130,8 +130,8 @@ namespace geode::utils::web {
AsyncExpectCode m_expect = nullptr; AsyncExpectCode m_expect = nullptr;
AsyncProgress m_progress = nullptr; AsyncProgress m_progress = nullptr;
AsyncCancelled m_cancelled = nullptr; AsyncCancelled m_cancelled = nullptr;
bool m_sent = false; AsyncWebRequestData* m_extra = nullptr;
mutable std::variant<std::monostate, AsyncWebRequestData> m_extra; std::variant<std::monostate, std::ostream*, ghc::filesystem::path> m_target;
std::vector<std::string> m_httpHeaders; std::vector<std::string> m_httpHeaders;
AsyncWebRequestData& extra(); AsyncWebRequestData& extra();

View file

@ -427,17 +427,17 @@ void SentAsyncWebRequest::error(std::string const& error, int code) {
} }
AsyncWebRequestData& AsyncWebRequest::extra() { AsyncWebRequestData& AsyncWebRequest::extra() {
if (!std::holds_alternative<AsyncWebRequestData>(m_extra)) { if (!m_extra) {
m_extra = AsyncWebRequestData(); m_extra = new AsyncWebRequestData();
} }
return std::get<AsyncWebRequestData>(m_extra); return *m_extra;
} }
AsyncWebRequestData const& AsyncWebRequest::extra() const { AsyncWebRequestData const& AsyncWebRequest::extra() const {
if (!std::holds_alternative<AsyncWebRequestData>(m_extra)) { if (!m_extra) {
m_extra = AsyncWebRequestData(); m_extra = new AsyncWebRequestData();
} }
return std::get<AsyncWebRequestData>(m_extra); return *m_extra;
} }
AsyncWebRequest& AsyncWebRequest::join(std::string const& requestID) { AsyncWebRequest& AsyncWebRequest::join(std::string const& requestID) {
@ -503,8 +503,8 @@ AsyncWebRequest& AsyncWebRequest::cancelled(AsyncCancelled cancelledFunc) {
} }
SentAsyncWebRequestHandle AsyncWebRequest::send() { SentAsyncWebRequestHandle AsyncWebRequest::send() {
if (m_sent) return nullptr; if (this->extra().m_sent) return nullptr;
m_sent = true; this->extra().m_sent = true;
std::lock_guard __(RUNNING_REQUESTS_MUTEX); std::lock_guard __(RUNNING_REQUESTS_MUTEX);