| 62 | } |
| 63 | |
| 64 | bool Response::verifyMD5(bool fail_if_header_missing, Optional<std::string> content_sum) { |
| 65 | auto i = headers.find("Content-MD5"); |
| 66 | if (i != headers.end()) { |
| 67 | // If a content sum is not provided, calculate one from the response content |
| 68 | if (!content_sum.present()) { |
| 69 | MD5_CTX sum; |
| 70 | ::MD5_Init(&sum); |
| 71 | ::MD5_Update(&sum, content.data(), content.size()); |
| 72 | std::string sumBytes; |
| 73 | sumBytes.resize(16); |
| 74 | ::MD5_Final((unsigned char*)sumBytes.data(), &sum); |
| 75 | std::string sumStr = base64::encoder::from_string(sumBytes); |
| 76 | sumStr.resize(sumStr.size() - 1); |
| 77 | content_sum = sumStr; |
| 78 | } |
| 79 | return i->second == content_sum.get(); |
| 80 | } |
| 81 | return !fail_if_header_missing; |
| 82 | } |
| 83 | |
| 84 | std::string Response::toString() { |
| 85 | std::string r = format("Response Code: %d\n", code); |
no test coverage detected