HCCallPerformFunction
Performs an HTTP call for libHttpClient. Register this callback with HCSetHttpCallPerformFunction to replace the built-in HTTP implementation, or to filter calls before you pass them to the built-in implementation.Syntax
Parameters
call   _In_Type: HCCallHandle The handle of the HTTP call to perform. asyncBlock   _Inout_
Type: XAsyncBlock* The async block for this attempt of the HTTP call. Complete it by calling
XAsyncComplete when the attempt finishes.
context   _In_opt_Type: void* The
performContext value that you passed to HCSetHttpCallPerformFunction.
env   _In_opt_Type: HCPerformEnv An opaque value for the default perform function. If your callback is a filter that forwards the call to the function returned by HCGetHttpCallPerformFunction, pass
env to that function unchanged. Otherwise, ignore it.
Return value
Type: voidRemarks
Call HCSetHttpCallPerformFunction before HCInitialize. After libHttpClient is initialized, HCSetHttpCallPerformFunction returnsE_HC_ALREADY_INITIALISED.
libHttpClient calls this callback once for each attempt that it sends through the HTTP provider for a call that you start with HCHttpCallPerformAsync. When libHttpClient retries a call, it calls the callback again with a new asyncBlock. Calls that complete without sending a request through the provider, such as calls that match a mock added with HCMockAddMock, don’t reach this callback.
To implement the callback:
- Read the request with the
HCHttpCallRequestGet*functions, such as HCHttpCallRequestGetUrl, HCHttpCallRequestGetNumHeaders, HCHttpCallRequestGetHeaderAtIndex, and HCHttpCallRequestGetRequestBodyReadFunction. - Send the request with your HTTP stack. Return from the callback promptly and do the network work asynchronously.
- Set the response with the
HCHttpCallResponseSet*functions, such as HCHttpCallResponseSetStatusCode and HCHttpCallResponseSetHeader. Write the response body through the function returned by HCHttpCallResponseGetResponseBodyWriteFunction. - If a network error occurs, call HCHttpCallResponseSetNetworkErrorCode.
- Call
XAsyncComplete(asyncBlock, S_OK, 0)to finish the attempt, including when you reported a network error in step 4. libHttpClient decides whether to retry from the network error and status code that you set on the response. Complete with a failure HRESULT only if your provider itself fails internally. Doing so skips automatic retry and fails the call to HCHttpCallPerformAsync with that HRESULT.
noexcept boundary, so an escaping exception terminates the process instead of failing the attempt.
Example
The following filter shows where to log each request before it forwards the request to the default implementation.Requirements
Header: httpProvider.h Library: libHttpClient.lib Supported platforms: Windows, XBOX One family consoles and XBOX Series consolesSee also
httpProviderHCSetHttpCallPerformFunction
HCGetHttpCallPerformFunction
