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 committed Apr 10, 2024
1 parent ed055a8 commit 7406b3a
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",
"dupenv", "USERPROFILE", "subblock", "LANGANDCODEPAGE", "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 @@ -54,6 +54,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 @@ -52,6 +52,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 @@ -93,6 +95,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 @@ -250,6 +250,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 @@ -73,7 +73,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 @@ -352,6 +360,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 7406b3a

Please sign in to comment.