| 79 | } |
| 80 | |
| 81 | bool HttpFetcher::FetchBody(HINTERNET request, std::vector<uint8_t> & response) |
| 82 | { |
| 83 | wchar_t contentLengthStr[32]; |
| 84 | DWORD contentLengthLength = sizeof(contentLengthStr); |
| 85 | auto gotLength = WinHttpQueryHeaders(request, WINHTTP_QUERY_CONTENT_LENGTH, |
| 86 | NULL, contentLengthStr, &contentLengthLength, 0); |
| 87 | if (gotLength != TRUE) { |
| 88 | return false; |
| 89 | } |
| 90 | |
| 91 | auto contentLength = (uint32_t)std::stoi(contentLengthStr); |
| 92 | if (contentLength > 0x1000000) { |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | response.resize(contentLength); |
| 97 | DWORD totalBytesRead = 0; |
| 98 | |
| 99 | while (totalBytesRead < contentLength) { |
| 100 | DWORD bytesToRead = contentLength - totalBytesRead; |
| 101 | DWORD bytesRead = 0; |
| 102 | auto readBytes = WinHttpReadData(request, response.data() + totalBytesRead, |
| 103 | bytesToRead, &bytesRead); |
| 104 | if (readBytes != TRUE) { |
| 105 | return false; |
| 106 | } |
| 107 | |
| 108 | totalBytesRead += bytesRead; |
| 109 | } |
| 110 | |
| 111 | return true; |
| 112 | } |
| 113 | |
| 114 | bool HttpFetcher::FetchETag(HINTERNET request, std::string & etag) |
| 115 | { |
nothing calls this directly
no outgoing calls
no test coverage detected