Skylicht Engine
Toggle main menu visibility
Loading...
Searching...
No Matches
HttpRequest
CEmscriptenHttpRequest.h
1
// CEmscriptenHttpRequest.h / .cpp
2
// Backend: emscripten/fetch.h
3
// Drop-in replacement implementing Skylicht::Network::IHttpRequest for Web builds
4
// Notes:
5
// - Supports GET, POST (x-www-form-urlencoded), POST JSON, PUT JSON, DELETE
6
// - Streams response data into provided IHttpStream (same as CHttpRequest)
7
// - Sets HTTP status code via getResponseCode()
8
// - Header support using emscripten_fetch "requestHeaders" (pairs: key, value, ..., 0)
9
// - File uploads via multipart are not implemented in this minimal version (see TODO)
10
// - Requires building with Emscripten and -sFETCH=1
11
12
#pragma once
13
14
#ifdef __EMSCRIPTEN__
15
16
#include <emscripten/fetch.h>
17
#include "IHttpRequest.h"
18
19
namespace
Skylicht
20
{
21
namespace
Network
22
{
23
class
CEmscriptenHttpRequest :
public
IHttpRequest
24
{
25
public
:
26
CEmscriptenHttpRequest(IHttpStream* stream);
27
28
~CEmscriptenHttpRequest();
29
30
virtual
void
sendRequest();
31
32
virtual
bool
updateRequest();
33
34
virtual
void
cancel();
35
36
virtual
bool
isCancel()
37
{
38
return
m_isCancel;
39
}
40
41
virtual
unsigned
long
getSpeedDownload()
42
{
43
return
m_bytePerSecond;
44
}
45
46
virtual
bool
isTimeOut()
47
{
48
return
m_isTimeOut;
49
}
50
51
private
:
52
53
std::string buildBody(
bool
json);
54
55
void
startFetch(
const
char
* method,
bool
json);
56
57
static
void
OnSuccess(emscripten_fetch_t* fetch);
58
59
static
void
OnError(emscripten_fetch_t* fetch);
60
61
static
void
OnProgress(emscripten_fetch_t* fetch);
62
63
protected
:
64
65
inline
long
getCurrentTimeOut()
66
{
67
return
m_currentTime - m_revcTime;
68
}
69
70
inline
long
getTimeOut()
71
{
72
return
m_requestTimeOut;
73
}
74
75
private
:
76
std::string m_bodyBuffer;
77
78
bool
m_isCancel;
79
bool
m_isTimeOut;
80
81
unsigned
long
m_requestTime;
82
unsigned
long
m_time;
83
unsigned
long
m_revcTime;
84
unsigned
long
m_currentTime;
85
unsigned
long
m_requestTimeOut;
86
87
unsigned
long
m_totalBytePerSecond;
88
unsigned
long
m_bytePerSecond;
89
90
emscripten_fetch_t* m_fetch;
91
std::vector<std::string> m_headerKV;
// key, value, key, value ...
92
std::vector<const char*> m_headerPtrs;
// pointers for attr.requestHeaders
93
};
94
}
95
}
96
97
#endif
// __EMSCRIPTEN__
Skylicht::Network::IHttpRequest
Definition
IHttpRequest.h:35
Skylicht
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition
AudioDebugLog.h:29
Generated by
1.17.0