yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
emscripten_http_client.h
Go to the documentation of this file.
1#ifndef YAZE_APP_NET_WASM_EMSCRIPTEN_HTTP_CLIENT_H_
2#define YAZE_APP_NET_WASM_EMSCRIPTEN_HTTP_CLIENT_H_
3
4#ifdef __EMSCRIPTEN__
5
6#include <mutex>
7#include <condition_variable>
8
9#include <emscripten/fetch.h>
10
11#include "app/net/http_client.h"
12
13namespace yaze {
14namespace net {
15
23class EmscriptenHttpClient : public IHttpClient {
24 public:
25 EmscriptenHttpClient();
26 ~EmscriptenHttpClient() override;
27
34 absl::StatusOr<HttpResponse> Get(
35 const std::string& url,
36 const Headers& headers = {}) override;
37
45 absl::StatusOr<HttpResponse> Post(
46 const std::string& url,
47 const std::string& body,
48 const Headers& headers = {}) override;
49
57 absl::StatusOr<HttpResponse> Put(
58 const std::string& url,
59 const std::string& body,
60 const Headers& headers = {}) override;
61
68 absl::StatusOr<HttpResponse> Delete(
69 const std::string& url,
70 const Headers& headers = {}) override;
71
72 private:
76 struct FetchResult {
77 bool completed = false;
78 bool success = false;
79 int status_code = 0;
80 std::string body;
81 Headers headers;
82 std::string error_message;
83 std::mutex mutex;
84 std::condition_variable cv;
85 };
86
95 absl::StatusOr<HttpResponse> PerformFetch(
96 const std::string& method,
97 const std::string& url,
98 const std::string& body = "",
99 const Headers& headers = {});
100
104 static void OnFetchSuccess(emscripten_fetch_t* fetch);
105
109 static void OnFetchError(emscripten_fetch_t* fetch);
110
114 static void OnFetchProgress(emscripten_fetch_t* fetch);
115};
116
117} // namespace net
118} // namespace yaze
119
120#endif // __EMSCRIPTEN__
121
122#endif // YAZE_APP_NET_WASM_EMSCRIPTEN_HTTP_CLIENT_H_
std::map< std::string, std::string > Headers
HTTP headers type definition.
Definition http_client.h:16