Skip to main content

HCMockMatchedCallback

Callback that’s invoked when a mock is matched, before libHttpClient copies the mock response to the call.

Syntax

Parameters

matchedMock   _In_
Type: HCMockCallHandle
The mock that matched the HTTP call. method   _In_
Type: const char*
The UTF-8 encoded HTTP method of the original call. url   _In_
Type: const char*
The UTF-8 encoded URL of the original call. requestBodyBytes   _In_
Type: const uint8_t*
The request body of the original call. requestBodySize   _In_
Type: uint32_t
The size of requestBodyBytes, in bytes. This value is 0 if the original call has no request body. context   _In_
Type: void*
The client context that you passed to HCMockSetMockMatchedCallback.

Return value

Type: void

Remarks

To register this callback for a mock, call HCMockSetMockMatchedCallback. When a request attempt started by HCHttpCallPerformAsync matches a mock that you added with HCMockAddMock, libHttpClient invokes the callback before it copies the mock response to that attempt. This gives you another opportunity to set the mock response. For example, inspect url or requestBodyBytes, and then call HCMockResponseSetResponseBodyBytes, HCMockResponseSetStatusCode, HCMockResponseSetHeader, or HCMockResponseSetNetworkErrorCode on matchedMock. After the callback returns, libHttpClient copies the mock’s current response to the current request attempt. If more than one mock matches the call, libHttpClient invokes the callback only for the mock that it selects for the attempt. If libHttpClient retries the call automatically, a later attempt can select a mock and invoke a callback again. The requestBodyBytes buffer is a temporary copy that’s valid only until the callback returns. Copy the data if you need it later. libHttpClient reads the full request body of the original call before it invokes the callback. If it can’t read the request body, it doesn’t invoke the callback and doesn’t use the mock for that attempt. The callback runs synchronously on a thread that dispatches the work port of the task queue for the call. libHttpClient holds its internal mock lock while the callback runs, so return quickly and don’t block.

Requirements

Header: mock.h Library: libHttpClient.lib Supported platforms: Windows, XBOX One family consoles and XBOX Series consoles

See also

mock
HCMockSetMockMatchedCallback
HCMockAddMock
HCHttpCallPerformAsync
Last modified on October 30, 2026