From dbc1d9c40e0c8dfdd8a22d7c328dd630ae457ffd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 5 Jan 2021 00:38:16 +0100 Subject: [PATCH] Fix cancelling wxWebRequest under MSW A cancelled request is not supposed to end up in the "failed" state, but it did, resulting in showing an error in the webrequest sample after pressing on the "Cancel" button, which was clearly unwanted. --- src/msw/webrequest_winhttp.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/msw/webrequest_winhttp.cpp b/src/msw/webrequest_winhttp.cpp index 49504568aa..46ed71bd7a 100644 --- a/src/msw/webrequest_winhttp.cpp +++ b/src/msw/webrequest_winhttp.cpp @@ -190,7 +190,13 @@ void wxWebRequestWinHTTP::HandleCallback(DWORD dwInternetStatus, case WINHTTP_CALLBACK_STATUS_REQUEST_ERROR: { LPWINHTTP_ASYNC_RESULT asyncResult = reinterpret_cast(lpvStatusInformation); - SetState(wxWebRequest::State_Failed, wxWinHTTPErrorToString(asyncResult->dwError)); + // "Failing" with "cancelled" error is not actually an error if + // we're expecting it, i.e. if our Cancel() had been called. + if ( asyncResult->dwError == ERROR_WINHTTP_OPERATION_CANCELLED && + GetState() == wxWebRequest::State_Cancelled ) + SetState(wxWebRequest::State_Cancelled); + else + SetState(wxWebRequest::State_Failed, wxWinHTTPErrorToString(asyncResult->dwError)); break; } }