MCPcopy Create free account
hub / github.com/ClassiCube/ClassiCube / Http_Add

Function Http_Add

src/_HttpBase.h:247–287  ·  view source on GitHub ↗

Adds a req to the list of pending requests, waking up worker thread if needed. */

Source from the content-addressed store, hash-verified

245
246/* Adds a req to the list of pending requests, waking up worker thread if needed. */
247static int Http_Add(const cc_string* url, cc_uint8 flags, cc_uint8 type, const cc_string* lastModified,
248 const cc_string* etag, const void* data, cc_uint32 size, struct StringsBuffer* cookies) {
249 static const cc_string https = String_FromConst("https://");
250 static const cc_string http = String_FromConst("http://");
251 struct HttpRequest req = { 0 };
252
253 String_CopyToRawArray(req.url, url);
254 Platform_Log2("Adding %s (type %b)", url, &type);
255
256 req.id = ++nextReqID;
257 req.requestType = type;
258
259 /* Change http:// to https:// if required */
260 if (httpsOnly) {
261 cc_string url_ = String_FromRawArray(req.url);
262 if (String_CaselessStarts(&url_, &http)) String_InsertAt(&url_, 4, 's');
263 }
264 /* Change https:// to http:// if required */
265 if (httpOnly) {
266 cc_string url_ = String_FromRawArray(req.url);
267 if (String_CaselessStarts(&url_, &https)) String_DeleteAt(&url_, 4);
268 }
269
270 if (lastModified) {
271 String_CopyToRawArray(req.lastModified, lastModified);
272 }
273 if (etag) {
274 String_CopyToRawArray(req.etag, etag);
275 }
276
277 if (data) {
278 req.data = (cc_uint8*)Mem_Alloc(size, 1, "Http_PostData");
279 Mem_Copy(req.data, data, size);
280 req.size = size;
281 }
282 req.cookies = cookies;
283 req.progress = HTTP_PROGRESS_NOT_WORKING_ON;
284
285 HttpBackend_Add(&req, flags);
286 return req.id;
287}
288
289
290/* Updates state after a completed http request */

Callers 4

Http_AsyncGetDataFunction · 0.85
Http_AsyncGetHeadersFunction · 0.85
Http_AsyncPostDataFunction · 0.85
Http_AsyncGetDataExFunction · 0.85

Calls 7

Platform_Log2Function · 0.85
String_CaselessStartsFunction · 0.85
String_InsertAtFunction · 0.85
String_DeleteAtFunction · 0.85
Mem_AllocFunction · 0.85
Mem_CopyFunction · 0.85
HttpBackend_AddFunction · 0.70

Tested by

no test coverage detected