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.
This commit is contained in:
Vadim Zeitlin
2021-01-05 00:38:16 +01:00
parent dd23d2cf25
commit dbc1d9c40e

View File

@@ -190,7 +190,13 @@ void wxWebRequestWinHTTP::HandleCallback(DWORD dwInternetStatus,
case WINHTTP_CALLBACK_STATUS_REQUEST_ERROR: case WINHTTP_CALLBACK_STATUS_REQUEST_ERROR:
{ {
LPWINHTTP_ASYNC_RESULT asyncResult = reinterpret_cast<LPWINHTTP_ASYNC_RESULT>(lpvStatusInformation); LPWINHTTP_ASYNC_RESULT asyncResult = reinterpret_cast<LPWINHTTP_ASYNC_RESULT>(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; break;
} }
} }