| 367 | } |
| 368 | |
| 369 | void CHttpRequest::OnCompletionInternal(void *pHandle, unsigned int Result) |
| 370 | { |
| 371 | if(pHandle) |
| 372 | { |
| 373 | CURL *pH = (CURL *)pHandle; |
| 374 | long StatusCode; |
| 375 | curl_easy_getinfo(pH, CURLINFO_RESPONSE_CODE, &StatusCode); |
| 376 | m_StatusCode = StatusCode; |
| 377 | } |
| 378 | |
| 379 | EHttpState State; |
| 380 | const CURLcode Code = static_cast<CURLcode>(Result); |
| 381 | if(Code != CURLE_OK) |
| 382 | { |
| 383 | if(g_Config.m_DbgCurl || m_LogProgress >= HTTPLOG::FAILURE) |
| 384 | { |
| 385 | log_error("http", "%s failed. libcurl error (%u): %s", m_aUrl, Code, m_aErr[0] != '\0' ? m_aErr : curl_easy_strerror(Code)); |
| 386 | } |
| 387 | State = (Code == CURLE_ABORTED_BY_CALLBACK) ? EHttpState::ABORTED : EHttpState::ERROR; |
| 388 | } |
| 389 | else |
| 390 | { |
| 391 | if(g_Config.m_DbgCurl || m_LogProgress >= HTTPLOG::ALL) |
| 392 | { |
| 393 | log_info("http", "task done: %s", m_aUrl); |
| 394 | } |
| 395 | State = EHttpState::DONE; |
| 396 | } |
| 397 | |
| 398 | if(State == EHttpState::DONE) |
| 399 | { |
| 400 | m_ActualSha256 = sha256_finish(&m_ActualSha256Ctx); |
| 401 | if(m_ExpectedSha256.has_value() && m_ActualSha256.value() != m_ExpectedSha256.value()) |
| 402 | { |
| 403 | if(g_Config.m_DbgCurl || m_LogProgress >= HTTPLOG::FAILURE) |
| 404 | { |
| 405 | char aActualSha256[SHA256_MAXSTRSIZE]; |
| 406 | sha256_str(m_ActualSha256.value(), aActualSha256, sizeof(aActualSha256)); |
| 407 | char aExpectedSha256[SHA256_MAXSTRSIZE]; |
| 408 | sha256_str(m_ExpectedSha256.value(), aExpectedSha256, sizeof(aExpectedSha256)); |
| 409 | log_error("http", "SHA256 mismatch: got=%s, expected=%s, url=%s", aActualSha256, aExpectedSha256, m_aUrl); |
| 410 | } |
| 411 | State = EHttpState::ERROR; |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | if(m_WriteToFile) |
| 416 | { |
| 417 | if(m_File && io_close(m_File) != 0) |
| 418 | { |
| 419 | log_error("http", "i/o error, cannot close file: %s", m_aDest); |
| 420 | State = EHttpState::ERROR; |
| 421 | } |
| 422 | m_File = nullptr; |
| 423 | |
| 424 | if(State == EHttpState::ERROR || State == EHttpState::ABORTED) |
| 425 | { |
| 426 | fs_remove(m_aDestAbsoluteTmp); |
no test coverage detected