---
title: "Advanced HTTP control"
slug: "advanced-http-control"
abstract: "Overview of the custom DelegationHandler and custom HTTPClient."
---
# Advanced HTTP control

The Web SDK allows the consumers to have full control over the requests, the responses and even the HTTPClient from the SDK.

> [!note]
> The `client` variable in the following code examples refers to the `IMClient` instance. When using the Web SDK, the variable name can be chosen freely, but it is also called `client` at instantiation in the documentation.

It is recommended to set the `Accept` header to `application/json`.

## Using a custom DelegationHandler

To inject a custom `DelegatingHandler`, first create an implementation of the `Stylelabs.M.Sdk.WebClient.Http.IDelegatingHandlerFactory` interface.

To register the factory:

```shell
MClient.SetDelegatingHandlerFactory(myDelegationHandlerFactory);

```

> [!important]
> This should be the first thing after creating the `IWebMClient` instance. Once the client has executed its first HTTP request, the delegating handler will be re-used and the factory will not be called anymore.

## Using a custom HTTPClient

To inject a custom `HTTPClient`, first create an implementation of the `Stylelabs.M.Sdk.WebClient.Http.IHttpClientFactory` interface.

To register the factory:

```shell
MClient.SetHttpClientFactory(myHttpClientFactory);

```

> [!important]
> This should be the first thing after creating the `IWebMClient` instance. Once the client has executed its first HTTP request, the `HTTPClient` will be re-used and the factory will not be called anymore.