Polyphase Game Engine
Loading...
Searching...
No Matches
HttpClient.h
Go to the documentation of this file.
1#pragma once
2
3#if EDITOR
4
5#include <string>
6#include <functional>
7#include <atomic>
8
12struct HttpResponse
13{
14 int mStatusCode = 0;
15 std::string mBody;
16 std::string mError;
17
18 bool IsSuccess() const
19 {
20 return mStatusCode >= 200 && mStatusCode < 300;
21 }
22};
23
29using DownloadProgressCallback = std::function<void(size_t downloaded, size_t total)>;
30
37class HttpClient
38{
39public:
45 static bool IsAvailable();
46
51 static std::string GetMissingDependencyMessage();
52
59 static HttpResponse Get(const std::string& url, int timeoutMs = 10000);
60
69 static bool DownloadFile(
70 const std::string& url,
71 const std::string& destPath,
72 DownloadProgressCallback progressCallback,
73 std::atomic<bool>& cancelFlag);
74
75private:
76 // Platform-specific initialization
77 static bool InitializePlatform();
78 static void ShutdownPlatform();
79
80 static bool sInitialized;
81 static bool sAvailable;
82};
83
84#endif // EDITOR
Definition HttpResponse.h:16
bool IsSuccess() const
Definition HttpResponse.h:27
bool IsAvailable()
Definition HttpClient.cpp:224
const char * GetMissingDependencyMessage()
Definition HttpClient.cpp:231