Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions Release/src/http/client/http_client_winhttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1723,23 +1723,27 @@ class winhttp_client final : public _http_client_communicator
}
}

static utility::string_t get_request_url(HINTERNET hRequestHandle)
static std::wstring get_request_url(HINTERNET hRequestHandle)
{
DWORD urlSize{ 0 };
if(FALSE == WinHttpQueryOption(hRequestHandle, WINHTTP_OPTION_URL, nullptr, &urlSize) || urlSize == 0)
std::wstring url;
auto urlSize = static_cast<unsigned long>(url.capacity()) * 2; // use initial small string optimization capacity
for (;;)
{
return U("");
}

auto urlwchar = new WCHAR[urlSize / sizeof(WCHAR)];

WinHttpQueryOption(hRequestHandle, WINHTTP_OPTION_URL, (void*)urlwchar, &urlSize);

utility::string_t url(urlwchar);

delete[] urlwchar;
url.resize(urlSize / sizeof(wchar_t));
if (WinHttpQueryOption(hRequestHandle, WINHTTP_OPTION_URL, &url[0], &urlSize))
{
url.resize(wcslen(url.c_str()));
return url;
}

return url;
const auto lastError = GetLastError();
if (lastError != ERROR_INSUFFICIENT_BUFFER || urlSize == 0)
{
url.clear();
url.shrink_to_fit();
return url;
}
}
}

// Returns true if we handle successfully and resending the request
Expand Down