-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathhttp.inc
More file actions
executable file
·276 lines (248 loc) · 8.87 KB
/
http.inc
File metadata and controls
executable file
·276 lines (248 loc) · 8.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
// Define a typeset for HTTP response callbacks
typeset ResponseCallback
{
/**
* Function called when an HTTP response is received
*
* @param http HTTP request object
* @param body Response body
* @param statusCode HTTP status code
* @param bodySize Size of the response body
* @param value Value passed to the HTTP method
*/
function void (HttpRequest http, const char[] body, int statusCode, int bodySize, any value);
}
methodmap HttpRequest < Handle
{
/**
* Create a new HTTP request
*
* @param url Request URL
*/
public native HttpRequest(const char[] url);
/**
* Performs a GET request
* GET requests should not have a body, only query parameters in URL
*
* @param fResponse Function to call when an HTTP response is received
* @param value Value to pass to the callback
* @return True if the request was sent successfully, false otherwise
*/
public native bool Get(ResponseCallback fResponse, any value = 0);
/**
* Performs a POST request with JSON body
* POST requests typically send data to create a new resource
*
* @param json JSON data to send in request body
* @param fResponse Function to call when an HTTP response is received
* @param value Value to pass to the callback
* @return True if the request was sent successfully, false otherwise
*/
public native bool PostJson(const JSON json, ResponseCallback fResponse, any value = 0);
/**
* Performs a POST request with accumulated form parameters
* Uses application/x-www-form-urlencoded format
*
* @param fResponse Function to call when an HTTP response is received
* @param value Value to pass to the callback
* @return True if the request was sent successfully, false otherwise
*/
public native bool PostForm(ResponseCallback fResponse, any value = 0);
/**
* Performs a PUT request with JSON body
* PUT requests typically update an entire resource
*
* @param json JSON data to send in request body
* @param fResponse Function to call when an HTTP response is received
* @param value Value to pass to the callback
* @return True if the request was sent successfully, false otherwise
*/
public native bool PutJson(const JSON json, ResponseCallback fResponse, any value = 0);
/**
* Performs a PATCH request with JSON body
* PATCH requests typically perform partial updates to a resource
*
* @param json JSON data containing the fields to update
* @param fResponse Function to call when an HTTP response is received
* @param value Value to pass to the callback
* @return True if the request was sent successfully, false otherwise
*/
public native bool PatchJson(const JSON json, ResponseCallback fResponse, any value = 0);
/**
* Performs a DELETE request
* DELETE requests typically don't have a body
*
* @param fResponse Function to call when an HTTP response is received
* @param value Value to pass to the callback
* @return True if the request was sent successfully, false otherwise
*/
public native bool Delete(ResponseCallback fResponse, any value = 0);
/**
* Append a form parameter to the request
* Multiple calls will accumulate parameters for the next form submission
*
* @param key Parameter key
* @param value Parameter value
* @return True if parameter was added successfully
*/
public native bool AppendFormParam(const char[] key, const char[] value);
/**
* Add a header to the HTTP request
*
* @param key Header key
* @param value Header value
*/
public native void AddHeader(const char[] key, const char[] value);
/**
* Get a response header from the HTTP request
*
* @param key Header key
* @param value Buffer to store the header value
* @param maxLength Maximum length of the value buffer
* @return True if the header was found, false otherwise
*/
public native bool GetResponseHeader(const char[] key, char[] value, int maxLength);
/**
* Check if a response header exists in the HTTP request
*
* @param key Header key
* @return True if the header exists, false otherwise
*/
public native bool HasResponseHeader(const char[] key);
/**
* Get or set the connection timeout in milliseconds
*
* @note Default timeout varies by platform
*/
property int Timeout {
public native get();
public native set(int timeout);
}
/**
* Get or set whether to follow HTTP redirects
*
* @note When enabled, automatically follows 3xx redirect responses
*/
property bool FollowRedirect {
public native get();
public native set(bool follow);
}
/**
* Get or set whether to enable response compression
*
* @note Supports gzip and deflate compression
*/
property bool Compression {
public native get();
public native set(bool compress);
}
/**
* Get or set the maximum number of redirects to follow
*
* @note Only applies when FollowRedirect is enabled
*/
property int MaxRedirects {
public native get();
public native set(int maxRedirects);
}
/**
* Get or set verbose mode for debugging
*
* @note When enabled, prints detailed request/response information
*/
property bool Verbose {
public native get();
public native set(bool verbose);
}
/**
* Set TLS certificate and key files for client authentication
*
* @param certFile Path to certificate file (relative to game directory)
* @param keyFile Path to key file (relative to game directory)
* @note Used for mTLS when server requires client certificates
* @note Must be called before making requests
*/
public native void SetTLSCertAndKey(const char[] certFile, const char[] keyFile);
/**
* Set TLS CA file for server certificate verification
*
* @param caFile Path to CA file for verifying server certificates
* - "SYSTEM": Use system CA bundle to verify server (default, recommended)
* - "NONE": Disable server certificate verification (UNSAFE, testing only!)
* - Path: Custom CA file to trust specific server certificates
* @note Must be called before making requests
* @note This verifies the SERVER's identity when connecting via HTTPS
*/
public native void SetTLSCAFile(const char[] caFile);
/**
* Set TLS ciphers
*
* @param ciphers Cipher list (e.g., "DEFAULT", "rsa ...")
* @note Must be called before making requests
*/
public native void SetTLSCiphers(const char[] ciphers);
/**
* Get or set hostname validation for server certificates
*
* @note Must be called before making requests
* @note When true, verifies server certificate hostname matches the request URL
* @note Recommended: keep enabled (default) to prevent MITM attacks
*/
property bool HostnameValidation {
public native get();
public native set(bool enable);
}
/**
* Get or set HTTP Keep-Alive
*
* @note When enabled, reuses TCP connections for multiple requests
* @note Default: enabled
*/
property bool KeepAlive {
public native get();
public native set(bool enable);
}
/**
* Get or set whether to use connection pooling
*
* @note When enabled, connections are pooled and reused across requests
*/
property bool UseConnectionPool {
public native get();
public native set(bool enable);
}
/**
* Set proxy for HTTP requests
*
* @param proxyUrl Proxy URL (e.g., "http://proxy:8080", "socks5://proxy:1080")
* @note Supports HTTP, HTTPS, and SOCKS5 proxies
*/
public native void SetProxy(const char[] proxyUrl);
/**
* Clear proxy configuration
*/
public native void ClearProxy();
/**
* Check if proxy is configured
*/
property bool HasProxy {
public native get();
}
/**
* Set HTTP Basic authentication
*
* @param username Username for authentication
* @param password Password for authentication
*/
public native void SetBasicAuth(const char[] username, const char[] password);
/**
* Set HTTP Bearer token authentication
*
* @param token Bearer token for authentication
*/
public native void SetBearerAuth(const char[] token);
/**
* Clear authentication configuration
*/
public native void ClearAuth();
}