Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/src/duckstation-qt/asynchttprequest.h
15701 views
1
// SPDX-FileCopyrightText: 2019-2026 Connor McLaughlin <[email protected]>
2
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
3
4
#pragma once
5
6
#include "util/http_downloader.h"
7
8
#include "common/error.h"
9
10
#include <string>
11
#include <string_view>
12
13
#include <QtCore/QObject>
14
15
class QPixmap;
16
17
class AsyncHTTPRequest final : public QObject
18
{
19
Q_OBJECT
20
21
public:
22
AsyncHTTPRequest();
23
~AsyncHTTPRequest() override;
24
25
void get(std::string url, const void* owner, ProgressCallback* progress = nullptr,
26
HTTPDownloader::HeaderList additional_headers = {}, std::optional<u16> timeout_seconds = {});
27
void post(std::string url, std::string post_data, const void* owner, ProgressCallback* progress = nullptr,
28
HTTPDownloader::HeaderList additional_headers = {}, std::optional<u16> timeout_seconds = {});
29
30
Q_SIGNALS:
31
void requestComplete(qint32 status_code, Error& error_message, std::string& content_type,
32
HTTPDownloader::RequestData& data);
33
34
private:
35
void handleResponse(s32 status_code, Error& error, std::string& content_type, HTTPDownloader::RequestData& data);
36
void finishRequest();
37
38
s32 m_status_code = HTTPDownloader::HTTP_STATUS_ERROR;
39
Error m_error;
40
std::string m_content_type;
41
HTTPDownloader::RequestData m_data;
42
};
43
44