@@ -32,6 +32,9 @@ class WinInetRequestWrapper
32
32
HINTERNET m_hWinInetRequest {nullptr };
33
33
SimpleHttpRequest* m_request;
34
34
BYTE m_buffer[1024 ] {0 };
35
+ DWORD m_bufferUsed {0 };
36
+ std::vector<uint8_t > m_bodyBuffer;
37
+ bool m_readingData {false };
35
38
bool isCallbackCalled {false };
36
39
bool isAborted {false };
37
40
public:
@@ -316,20 +319,15 @@ class WinInetRequestWrapper
316
319
317
320
void onRequestComplete (DWORD dwError)
318
321
{
319
- std::unique_ptr<SimpleHttpResponse> response (new SimpleHttpResponse (m_id));
320
-
321
- std::vector<uint8_t > & m_bodyBuffer = response->m_body ;
322
- DWORD m_bufferUsed = 0 ;
323
-
324
322
if (dwError == ERROR_SUCCESS) {
325
323
// If looking good so far, try to fetch the response body first.
326
324
// It might potentially be another async operation which will
327
325
// trigger INTERNET_STATUS_REQUEST_COMPLETE again.
328
326
329
327
m_bodyBuffer.insert (m_bodyBuffer.end (), m_buffer, m_buffer + m_bufferUsed);
330
- do {
331
- m_bufferUsed = 0 ;
328
+ while (!m_readingData || m_bufferUsed != 0 ) {
332
329
BOOL bResult = ::InternetReadFile (m_hWinInetRequest, m_buffer, sizeof (m_buffer), &m_bufferUsed);
330
+ m_readingData = true ;
333
331
if (!bResult) {
334
332
dwError = GetLastError ();
335
333
if (dwError == ERROR_IO_PENDING) {
@@ -339,18 +337,22 @@ class WinInetRequestWrapper
339
337
// must stay valid and writable until the next
340
338
// INTERNET_STATUS_REQUEST_COMPLETE callback comes
341
339
// (that's why those are member variables).
340
+ LOG_TRACE (" InternetReadFile() failed: ERROR_IO_PENDING. Waiting for INTERNET_STATUS_REQUEST_COMPLETE to be called again" );
342
341
return ;
343
342
}
344
343
LOG_WARN (" InternetReadFile() failed: %d" , dwError);
345
344
break ;
346
345
}
347
346
348
347
m_bodyBuffer.insert (m_bodyBuffer.end (), m_buffer, m_buffer + m_bufferUsed);
349
- } while (m_bufferUsed == sizeof (m_buffer));
348
+ }
350
349
}
351
350
351
+ std::unique_ptr<SimpleHttpResponse> response (new SimpleHttpResponse (m_id));
352
+
352
353
// SUCCESS with no IO_PENDING means we're done with the response body: try to parse the response headers.
353
354
if (dwError == ERROR_SUCCESS) {
355
+ response->m_body = m_bodyBuffer;
354
356
response->m_result = HttpResult_OK;
355
357
356
358
uint32_t value = 0 ;
@@ -564,4 +566,3 @@ bool HttpClient_WinInet::IsMsRootCheckRequired()
564
566
#pragma warning(pop)
565
567
#endif // HAVE_MAT_DEFAULT_HTTP_CLIENT
566
568
// clang-format on
567
-
0 commit comments