Check for context cancellation in more places within the winhttp transport layer before each I/O call. (#2185)

* Check for context cancellation in more places within the winhttp transport layer before each I/O call.

* Update cspell to add exceptions to false positives.

* Address PR feedback.

* Do not check for context cancellation before querying the response headers.
This commit is contained in:
Ahson Khan 2021-05-05 17:17:54 -07:00 committed by GitHub
parent 22770cabbf
commit e1340dcfa8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

2
.vscode/cspell.json vendored
View File

@ -12,6 +12,8 @@
"ctest",
"moxygen",
"pwsh",
"SPDX",
"stoi",
"vcpkg"
],
"overrides": [

View File

@ -219,6 +219,8 @@ void WinHttpTransport::CreateConnectionHandle(
// If port is 0, i.e. INTERNET_DEFAULT_PORT, it uses port 80 for HTTP and port 443 for HTTPS.
uint16_t port = handleManager->m_request.GetUrl().GetPort();
handleManager->m_context.ThrowIfCancelled();
// Specify an HTTP server.
// This function always operates synchronously.
handleManager->m_connectionHandle = WinHttpConnect(
@ -296,6 +298,8 @@ void WinHttpTransport::Upload(std::unique_ptr<_detail::HandleManager>& handleMan
DWORD dwBytesWritten = 0;
handleManager->m_context.ThrowIfCancelled();
// Write data to the server.
if (!WinHttpWriteData(
handleManager->m_requestHandle,
@ -326,6 +330,8 @@ void WinHttpTransport::SendRequest(std::unique_ptr<_detail::HandleManager>& hand
int64_t streamLength = handleManager->m_request.GetBodyStream()->Length();
handleManager->m_context.ThrowIfCancelled();
// Send a request.
if (!WinHttpSendRequest(
handleManager->m_requestHandle,
@ -373,6 +379,8 @@ void WinHttpTransport::SendRequest(std::unique_ptr<_detail::HandleManager>& hand
void WinHttpTransport::ReceiveResponse(std::unique_ptr<_detail::HandleManager>& handleManager)
{
handleManager->m_context.ThrowIfCancelled();
// Wait to receive the response to the HTTP request initiated by WinHttpSendRequest.
// When WinHttpReceiveResponse completes successfully, the status code and response headers have
// been received.
@ -572,6 +580,9 @@ int64_t _detail::WinHttpStream::OnRead(uint8_t* buffer, int64_t count, Context c
DWORD numberOfBytesRead = 0;
// No need to check for context cancellation before the first I/O because the base class
// BodyStream::Read already does that.
// Check for available data.
DWORD numberOfBytesAvailable = 0;
if (!WinHttpQueryDataAvailable(this->m_handleManager->m_requestHandle, &numberOfBytesAvailable))