> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# HCMockMatchedCallback

> Lets a test inspect a matched HTTP call and change the mock response before libHttpClient copies it to the call.

# HCMockMatchedCallback

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

## Syntax

```cpp theme={null}
void CALLBACK HCMockMatchedCallback(  
         HCMockCallHandle matchedMock,  
         const char* method,  
         const char* url,  
         const uint8_t* requestBodyBytes,  
         uint32_t requestBodySize,  
         void* context  
)  
```

### 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](https://docs.xbox.com/reference/live/httpclient/mock/functions/hcmocksetmockmatchedcallback.md).

### Return value

Type: void

## Remarks

To register this callback for a mock, call [HCMockSetMockMatchedCallback](https://docs.xbox.com/reference/live/httpclient/mock/functions/hcmocksetmockmatchedcallback.md).

When a request attempt started by [HCHttpCallPerformAsync](https://docs.xbox.com/reference/live/httpclient/httpclient/functions/hchttpcallperformasync.md) matches a mock that you added with [HCMockAddMock](https://docs.xbox.com/reference/live/httpclient/mock/functions/hcmockaddmock.md), 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](https://docs.xbox.com/reference/live/httpclient/mock/functions/hcmockresponsesetresponsebodybytes.md), [HCMockResponseSetStatusCode](https://docs.xbox.com/reference/live/httpclient/mock/functions/hcmockresponsesetstatuscode.md), [HCMockResponseSetHeader](https://docs.xbox.com/reference/live/httpclient/mock/functions/hcmockresponsesetheader.md), or [HCMockResponseSetNetworkErrorCode](https://docs.xbox.com/reference/live/httpclient/mock/functions/hcmockresponsesetnetworkerrorcode.md) 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](https://docs.xbox.com/reference/live/httpclient/mock/mock_members.md)\
[HCMockSetMockMatchedCallback](https://docs.xbox.com/reference/live/httpclient/mock/functions/hcmocksetmockmatchedcallback.md)\
[HCMockAddMock](https://docs.xbox.com/reference/live/httpclient/mock/functions/hcmockaddmock.md)\
[HCHttpCallPerformAsync](https://docs.xbox.com/reference/live/httpclient/httpclient/functions/hchttpcallperformasync.md)


## Related topics

- [HCMockSetMockMatchedCallback](https://docs.xbox.com/reference/live/httpclient/mock/functions/hcmocksetmockmatchedcallback.md)
- [mock (contents)](https://docs.xbox.com/reference/live/httpclient/mock/mock_members.md)
- [HCMockAddMock](https://docs.xbox.com/reference/live/httpclient/mock/functions/hcmockaddmock.md)
- [HCMockRemoveMock](https://docs.xbox.com/reference/live/httpclient/mock/functions/hcmockremovemock.md)
- [HCMockClearMocks](https://docs.xbox.com/reference/live/httpclient/mock/functions/hcmockclearmocks.md)
