Adds a req to the list of pending requests, waking up worker thread if needed. */
| 245 | |
| 246 | /* Adds a req to the list of pending requests, waking up worker thread if needed. */ |
| 247 | static 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 */ |
no test coverage detected