MCPcopy Create free account
hub / github.com/Norbyte/ositools / FetchBody

Method FetchBody

OsiLoader/HttpFetcher.cpp:81–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79}
80
81bool 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
114bool HttpFetcher::FetchETag(HINTERNET request, std::string & etag)
115{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected