Skylicht Engine
Toggle main menu visibility
Loading...
Searching...
No Matches
HttpRequest
IHttpRequest.h
1
/*
2
!@
3
MIT License
4
5
Copyright (c) 2021 Skylicht Technology CO., LTD
6
7
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8
(the "Software"), to deal in the Software without restriction, including without limitation the Rights to use, copy, modify,
9
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10
subject to the following conditions:
11
12
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
14
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20
This file is part of the "Skylicht Engine".
21
https://github.com/skylicht-lab/skylicht-engine
22
!#
23
*/
24
25
#pragma once
26
27
#include "pch.h"
28
#include "IHttpStream.h"
29
30
namespace
Skylicht
31
{
32
namespace
Network
33
{
34
class
IHttpRequest
35
{
36
public
:
37
enum
ERequestType
38
{
39
Get = 0,
40
Post,
41
PostJson,
42
Put,
43
Delete
44
};
45
46
struct
SForm
47
{
48
std::string Name;
49
std::string Value;
50
bool
File;
51
52
SForm()
53
{
54
File =
false
;
55
}
56
};
57
58
protected
:
59
std::string m_url;
60
61
int
m_httpCode;
62
int
m_requestID;
63
64
ERequestType m_requestType;
65
IHttpStream
* m_dataStream;
66
67
// total size download
68
unsigned
long
m_downloading;
69
unsigned
long
m_total;
70
71
std::vector<SForm> m_post;
72
void
* m_userData;
73
74
std::vector<std::string> m_headers;
75
76
public
:
77
IHttpRequest(
IHttpStream
* stream);
78
79
virtual
~IHttpRequest();
80
81
static
IHttpRequest* create(
IHttpStream
* stream);
82
83
void
addFormRequest(
const
char
* name,
const
char
* value);
84
85
void
addFormFileRequest(
const
char
* name,
const
char
* value);
86
87
virtual
void
sendRequest() = 0;
88
89
virtual
bool
updateRequest() = 0;
90
91
virtual
void
cancel() = 0;
92
93
virtual
bool
isCancel()
94
{
95
return
false
;
96
}
97
98
virtual
bool
isTimeOut() = 0;
99
100
virtual
unsigned
long
getSpeedDownload()
101
{
102
return
0;
103
}
104
105
inline
void
setURL(
const
char
* url)
106
{
107
m_url = url;
108
}
109
110
inline
const
std::string& getURL()
111
{
112
return
m_url;
113
}
114
115
inline
void
setSendRequestType(ERequestType type)
116
{
117
m_requestType = type;
118
}
119
120
inline
void
setUserData(
void
* data)
121
{
122
m_userData = data;
123
}
124
125
inline
void
* getUserData()
126
{
127
return
m_userData;
128
}
129
130
inline
void
clearHeader()
131
{
132
m_headers.clear();
133
}
134
135
inline
void
addHeader(
const
char
* header)
136
{
137
m_headers.push_back(header);
138
}
139
140
inline
int
getResponseCode()
141
{
142
return
m_httpCode;
143
}
144
145
inline
IHttpStream* getStream()
146
{
147
return
m_dataStream;
148
}
149
150
inline
void
setRequestID(
int
id
)
151
{
152
m_requestID = id;
153
}
154
155
inline
int
getRequestID()
156
{
157
return
m_requestID;
158
}
159
160
inline
unsigned
long
getByteDownload()
161
{
162
return
m_downloading;
163
}
164
165
inline
unsigned
long
getTotalByteDownload()
166
{
167
return
m_total;
168
}
169
170
inline
void
updateStatusDownload(
unsigned
long
downLoad,
unsigned
long
total)
171
{
172
m_downloading = downLoad;
173
m_total = total;
174
}
175
176
static
std::string escapeJson(
const
std::string& s);
177
178
static
std::string urlEncode(
const
std::string& s);
179
};
180
}
181
}
Skylicht::Network::IHttpStream
Definition
IHttpStream.h:32
Skylicht
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition
AudioDebugLog.h:29
Generated by
1.17.0