Path: blob/master/src/duckstation-qt/asynchttprequest.cpp
15701 views
// SPDX-FileCopyrightText: 2019-2026 Connor McLaughlin <[email protected]>1// SPDX-License-Identifier: CC-BY-NC-ND-4.023#include "asynchttprequest.h"45#include "core/host.h"67#include "util/http_cache.h"8#include "util/http_downloader.h"910#include "common/error.h"11#include "common/log.h"1213#include "moc_asynchttprequest.cpp"1415LOG_CHANNEL(Host);1617AsyncHTTPRequest::AsyncHTTPRequest() : QObject()18{19}2021AsyncHTTPRequest::~AsyncHTTPRequest() = default;2223void AsyncHTTPRequest::get(std::string url, const void* owner, ProgressCallback* progress /* = nullptr */,24HTTPDownloader::HeaderList additional_headers /* = */,25std::optional<u16> timeout_seconds /* = */)26{27HTTPDownloader::CreateRequest(28std::move(url), owner,29[this](s32 status_code, Error& error, std::string& content_type, HTTPDownloader::RequestData& data) {30handleResponse(status_code, error, content_type, data);31},32progress, additional_headers, timeout_seconds);33}3435void AsyncHTTPRequest::post(std::string url, std::string post_data, const void* owner,36ProgressCallback* progress /* = nullptr */,37HTTPDownloader::HeaderList additional_headers /* = */,38std::optional<u16> timeout_seconds /* = */)39{40HTTPDownloader::CreatePostRequest(41std::move(url), std::move(post_data), owner,42[this](s32 status_code, Error& error, std::string& content_type, HTTPDownloader::RequestData& data) {43handleResponse(status_code, error, content_type, data);44},45progress, additional_headers, timeout_seconds);46}4748ALWAYS_INLINE_RELEASE void AsyncHTTPRequest::handleResponse(s32 status_code, Error& error, std::string& content_type,49HTTPDownloader::RequestData& data)50{51m_status_code = status_code;52m_error = std::move(error);53m_content_type = std::move(content_type);54m_data = std::move(data);55QMetaObject::invokeMethod(this, &AsyncHTTPRequest::finishRequest, Qt::QueuedConnection);56}5758void AsyncHTTPRequest::finishRequest()59{60emit requestComplete(m_status_code, m_error, m_content_type, m_data);61deleteLater();62}636465