| 161 | } |
| 162 | |
| 163 | void PlayFabHttp::ExecuteRequest(CallRequestContainer& reqContainer) |
| 164 | { |
| 165 | // Set up curl handle |
| 166 | reqContainer.curlHandle = curl_easy_init(); |
| 167 | curl_easy_reset(reqContainer.curlHandle); |
| 168 | curl_easy_setopt(reqContainer.curlHandle, CURLOPT_URL, PlayFabSettings::GetUrl(reqContainer.errorWrapper.UrlPath).c_str()); |
| 169 | |
| 170 | // Set up headers |
| 171 | reqContainer.curlHttpHeaders = nullptr; |
| 172 | reqContainer.curlHttpHeaders = curl_slist_append(reqContainer.curlHttpHeaders, "Accept: application/json"); |
| 173 | reqContainer.curlHttpHeaders = curl_slist_append(reqContainer.curlHttpHeaders, "Content-Type: application/json; charset=utf-8"); |
| 174 | reqContainer.curlHttpHeaders = curl_slist_append(reqContainer.curlHttpHeaders, ("X-PlayFabSDK: " + PlayFabSettings::versionString).c_str()); |
| 175 | reqContainer.curlHttpHeaders = curl_slist_append(reqContainer.curlHttpHeaders, "X-ReportErrorAsSuccess: true"); |
| 176 | if (reqContainer.authKey.length() != 0 && reqContainer.authValue.length() != 0) |
| 177 | reqContainer.curlHttpHeaders = curl_slist_append(reqContainer.curlHttpHeaders, (reqContainer.authKey + ": " + reqContainer.authValue).c_str()); |
| 178 | curl_easy_setopt(reqContainer.curlHandle, CURLOPT_HTTPHEADER, reqContainer.curlHttpHeaders); |
| 179 | |
| 180 | // Set up post & payload |
| 181 | std::string payload = reqContainer.errorWrapper.Request.toStyledString(); |
| 182 | curl_easy_setopt(reqContainer.curlHandle, CURLOPT_POST, nullptr); |
| 183 | curl_easy_setopt(reqContainer.curlHandle, CURLOPT_POSTFIELDS, payload.c_str()); |
| 184 | |
| 185 | // Process result |
| 186 | // TODO: CURLOPT_ERRORBUFFER ? |
| 187 | curl_easy_setopt(reqContainer.curlHandle, CURLOPT_TIMEOUT_MS, 10000L); |
| 188 | curl_easy_setopt(reqContainer.curlHandle, CURLOPT_WRITEDATA, &reqContainer); |
| 189 | curl_easy_setopt(reqContainer.curlHandle, CURLOPT_WRITEFUNCTION, CurlReceiveData); |
| 190 | |
| 191 | // Send |
| 192 | curl_easy_setopt(reqContainer.curlHandle, CURLOPT_SSL_VERIFYPEER, true); |
| 193 | const auto res = curl_easy_perform(reqContainer.curlHandle); |
| 194 | if (res != CURLE_OK) |
| 195 | { |
| 196 | reqContainer.errorWrapper.HttpCode = 408; |
| 197 | reqContainer.errorWrapper.HttpStatus = "Failed to contact server"; |
| 198 | reqContainer.errorWrapper.ErrorCode = PlayFabErrorConnectionTimeout; |
| 199 | reqContainer.errorWrapper.ErrorName = "Failed to contact server"; |
| 200 | reqContainer.errorWrapper.ErrorMessage = "Failed to contact server, curl error: " + std::to_string(res); |
| 201 | HandleCallback(reqContainer); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | void PlayFabHttp::HandleResults(CallRequestContainer& reqContainer) |
| 206 | { |
nothing calls this directly
no test coverage detected