Skip to content

Commit

Permalink
Fix keep alive setting on WinHTTP, trace more error codes from WinHTTP
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyRyabinin authored and Sergey Ryabinin committed May 23, 2024
1 parent ae2048f commit 3f114ec
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
// MSVC
"msvc", "MSFT", "LPDWORD", "DATAW", "mkgmtime", "vscprintf", "wtoi", "msxml", "runtimeobject", "winhttp",
"Wininet", "HINTERNET", "ADDREQ", "LPCSTR", "MAKELANGID", "SUBLANG", "WSADATA", "Initate", "ioctlsocket",
"dupenv", "USERPROFILE", "subblock", "LANGANDCODEPAGE", "CPPUNWIND",
"dupenv", "USERPROFILE", "subblock", "LANGANDCODEPAGE", "CPPUNWIND", "keepalivetime", "keepaliveinterval",
// Crypto
"decryptor", "encryptor", "NTSTATUS", "PBYTE", "PUCHAR", "noconf", "HAMC", "PBCRYPT", "BCRYPT", "libcrypto",
"AWSLC", "CBCCTS", "tweaklen", "taglen", "blockcipher", "AESGCM", "compated", "outdata", "Decrypto", "GCMAAD",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ namespace Aws
bool DoReadData(void* hHttpRequest, char* body, uint64_t size, uint64_t& read) const override;
void* GetClientModule() const override;

const char* GetActualHttpVersionUsed(void* hHttpRequest) const override;

bool m_usingProxy = false;
bool m_verifySSL = true;
Aws::Http::Version m_version = Aws::Http::Version::HTTP_VERSION_2TLS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ namespace Aws
bool DoReadData(void* hHttpRequest, char* body, uint64_t size, uint64_t& read) const override;
void* GetClientModule() const override;

const char* GetActualHttpVersionUsed(void* hHttpRequest) const override;

WinINetSyncHttpClient &operator =(const WinINetSyncHttpClient &rhs);

bool m_usingProxy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ namespace Aws
*/
bool m_allowRedirects;

bool m_enableHttpClientTrace = false;

private:
virtual void* OpenRequest(const std::shared_ptr<HttpRequest>& request, void* connection, const Aws::StringStream& ss) const = 0;
virtual void DoAddHeaders(void* hHttpRequest, Aws::String& headerStr) const = 0;
Expand All @@ -94,6 +96,8 @@ namespace Aws
virtual bool DoReadData(void* hHttpRequest, char* body, uint64_t size, uint64_t& read) const = 0;
virtual void* GetClientModule() const = 0;

virtual const char* GetActualHttpVersionUsed(void* hHttpRequest) const = 0;

bool StreamPayloadToRequest(const std::shared_ptr<HttpRequest>& request, void* hHttpRequest, Aws::Utils::RateLimits::RateLimiterInterface* writeLimiter) const;
void LogRequestInternalFailure() const;
bool BuildSuccessResponse(const std::shared_ptr<HttpRequest>& request, std::shared_ptr<Aws::Http::HttpResponse>& response, void* hHttpRequest, Aws::Utils::RateLimits::RateLimiterInterface* readLimiter) const;
Expand Down
206 changes: 179 additions & 27 deletions src/aws-cpp-sdk-core/source/http/windows/WinHttpSyncHttpClient.cpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ bool WinINetSyncHttpClient::DoReadData(void* hHttpRequest, char* body, uint64_t
return (InternetReadFile(hHttpRequest, body, (DWORD)size, (LPDWORD)&read) != 0);
}

const char* WinINetSyncHttpClient::GetActualHttpVersionUsed(void* hHttpRequest) const
{
AWS_UNREFERENCED_PARAM(hHttpRequest);
return "Unknown";
}

void* WinINetSyncHttpClient::GetClientModule() const
{
return GetModuleHandle(TEXT("wininet.dll"));
Expand Down
11 changes: 10 additions & 1 deletion src/aws-cpp-sdk-core/source/http/windows/WinSyncHttpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@ void WinSyncHttpClient::AddHeadersToRequest(const std::shared_ptr<HttpRequest>&
AWS_LOGSTREAM_DEBUG(GetLogTag(), "with headers:");
for (auto& header : request->GetHeaders())
{
ss << header.first << ": " << header.second << "\r\n";
if (!header.first.empty() && !header.second.empty())
{
ss << header.first << ": " << header.second << "\r\n";
}
else
{
// WinHttp does not accept empty header key or value
AWS_LOGSTREAM_DEBUG(GetLogTag(), "Empty header is ignored: " << header.first << ": " << header.second);
}
}

Aws::String headerString = ss.str();
Expand Down Expand Up @@ -402,6 +410,7 @@ std::shared_ptr<HttpResponse> WinSyncHttpClient::MakeRequest(const std::shared_p
}
else if(!success)
{
AWS_LOGSTREAM_INFO(GetLogTag(), "Actual HTTP Version used " << GetActualHttpVersionUsed(hHttpRequest));
LogRequestInternalFailure();
}

Expand Down

0 comments on commit 3f114ec

Please sign in to comment.