# Class ConfigurableMessageHandler (1.73.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [1.73.0 (latest)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.ConfigurableMessageHandler)
- [1.69.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.69.0/Google.Apis.Http.ConfigurableMessageHandler)
- [1.68.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.68.0/Google.Apis.Http.ConfigurableMessageHandler)
- [1.60.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.60.0/Google.Apis.Http.ConfigurableMessageHandler)
- [1.59.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.59.0/Google.Apis.Http.ConfigurableMessageHandler)
- [1.55.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.55.0/Google.Apis.Http.ConfigurableMessageHandler)
- [1.50.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.50.0/Google.Apis.Http.ConfigurableMessageHandler)

    public class ConfigurableMessageHandler : DelegatingHandler, IDisposable

A message handler which contains the main logic of our HTTP requests. It contains a list of
[IHttpUnsuccessfulResponseHandler](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpUnsuccessfulResponseHandler)s for handling abnormal responses, a list of
[IHttpExceptionHandler](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpExceptionHandler)s for handling exception in a request and a list of
[IHttpExecuteInterceptor](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpExecuteInterceptor)s for intercepting a request before it has been sent to the server.
It also contains important properties like number of tries, follow redirect, etc.

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> [HttpMessageHandler](https://learn.microsoft.com/dotnet/api/system.net.http.httpmessagehandler) \> [DelegatingHandler](https://learn.microsoft.com/dotnet/api/system.net.http.delegatinghandler) \> ConfigurableMessageHandler

## Implements

[IDisposable](https://learn.microsoft.com/dotnet/api/system.idisposable)

## Inherited Members

[DelegatingHandler.Dispose(bool)](https://learn.microsoft.com/dotnet/api/system.net.http.delegatinghandler.dispose) [DelegatingHandler.InnerHandler](https://learn.microsoft.com/dotnet/api/system.net.http.delegatinghandler.innerhandler) [HttpMessageHandler.Dispose()](https://learn.microsoft.com/dotnet/api/system.net.http.httpmessagehandler.dispose#system-net-http-httpmessagehandler-dispose) [object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)) [object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)) [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone) [object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Namespace

[Google.Apis.Http](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http)

## Assembly

Google.Apis.Core.dll

## Constructors

### ConfigurableMessageHandler(HttpMessageHandler)

    public ConfigurableMessageHandler(HttpMessageHandler httpMessageHandler)

Constructs a new configurable message handler.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `httpMessageHandler` | `https://learn.microsoft.com/dotnet/api/system.net.http.httpmessagehandler` |

## Fields

### CredentialKey

    public const string CredentialKey = "__CredentialKey"

Key for a credential in a [HttpRequestMessage](https://learn.microsoft.com/dotnet/api/system.net.http.httprequestmessage) options.

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### ExceptionHandlerKey

    public const string ExceptionHandlerKey = "__ExceptionHandlerKey"

Key for exception handlers in an [HttpRequestMessage](https://learn.microsoft.com/dotnet/api/system.net.http.httprequestmessage) options.

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### ExecuteInterceptorKey

    public const string ExecuteInterceptorKey = "__ExecuteInterceptorKey"

Key for execute handlers in an [HttpRequestMessage](https://learn.microsoft.com/dotnet/api/system.net.http.httprequestmessage) options.

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### MaxAllowedNumTries

    public const int MaxAllowedNumTries = 20

Maximum allowed number of tries.

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.int32` |   |

### MaxRetriesKey

    public const string MaxRetriesKey = "__MaxRetriesKey"

Key for request specific max retries.

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### ResponseStreamInterceptorProviderKey

    public const string ResponseStreamInterceptorProviderKey = "__ResponseStreamInterceptorProviderKey"

Key for a stream response interceptor provider in an [HttpRequestMessage](https://learn.microsoft.com/dotnet/api/system.net.http.httprequestmessage) options.

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### UnsuccessfulResponseHandlerKey

    public const string UnsuccessfulResponseHandlerKey = "__UnsuccessfulResponseHandlerKey"

Key for unsuccessful response handlers in an [HttpRequestMessage](https://learn.microsoft.com/dotnet/api/system.net.http.httprequestmessage) options.

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

## Properties

### ApplicationName

    public string ApplicationName { get; set; }

Gets or sets the application name which will be used on the User-Agent header.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### Credential

    public IHttpExecuteInterceptor Credential { get; set; }

The credential to apply to all requests made with this client,
unless theres a specific call credential set.
If [Credential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.ConfigurableMessageHandler#Google_Apis_Http_ConfigurableMessageHandler_Credential) implements [IHttpUnsuccessfulResponseHandler](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpUnsuccessfulResponseHandler)
then it will also be included as a handler of an unsuccessful response.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpExecuteInterceptor` |   |

### ExceptionHandlers

    [Obsolete("Use AddExceptionHandler or RemoveExceptionHandler instead.")]
    public IList<IHttpExceptionHandler> ExceptionHandlers { get; }

Gets a list of [IHttpExceptionHandler](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpExceptionHandler)s.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.collections.generic.ilist-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpExceptionHandler` |   |

### ExecuteInterceptors

    [Obsolete("Use AddExecuteInterceptor or RemoveExecuteInterceptor instead.")]
    public IList<IHttpExecuteInterceptor> ExecuteInterceptors { get; }

Gets a list of [IHttpExecuteInterceptor](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpExecuteInterceptor)s.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.collections.generic.ilist-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpExecuteInterceptor` |   |

### FollowRedirect

    public bool FollowRedirect { get; set; }

Gets or sets whether the handler should follow a redirect when a redirect response is received. Default
value is `true`.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` |   |

### GoogleApiClientHeader

    public string GoogleApiClientHeader { get; set; }

Gets or sets the value set for the x-goog-api-client header.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### IsLoggingEnabled

    public bool IsLoggingEnabled { get; set; }

Gets or sets whether logging is enabled. Default value is `true`.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.boolean` |   |

### LogEvents

    public ConfigurableMessageHandler.LogEventType LogEvents { get; set; }

The request/response types to log.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.ConfigurableMessageHandlerhttps://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.ConfigurableMessageHandler.LogEventType` |   |

### NumRedirects

    public int NumRedirects { get; set; }

Gets or sets the number of redirects that will be allowed to execute. The default value is `10`.
See [NumTries](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.ConfigurableMessageHandler#Google_Apis_Http_ConfigurableMessageHandler_NumTries) for more information.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.int32` |   |

### NumTries

    public int NumTries { get; set; }

Gets or sets the number of tries that will be allowed to execute. Retries occur as a result of either
[IHttpUnsuccessfulResponseHandler](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpUnsuccessfulResponseHandler) or [IHttpExceptionHandler](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpExceptionHandler) which handles the
abnormal HTTP response or exception before being terminated.
Set `1` for not retrying requests. The default value is `3`.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.int32` |   |

### UniverseDomain

    public string UniverseDomain { get; set; }

The universe domain to include as an option in the request.
This may be used by the [Credential](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.ConfigurableMessageHandler#Google_Apis_Http_ConfigurableMessageHandler_Credential) to validate against its own universe domain.
May be null, in which case no universe domain will be included in the request.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.string` |   |

### UnsuccessfulResponseHandlers

    [Obsolete("Use AddUnsuccessfulResponseHandler or RemoveUnsuccessfulResponseHandler instead.")]
    public IList<IHttpUnsuccessfulResponseHandler> UnsuccessfulResponseHandlers { get; }

Gets a list of [IHttpUnsuccessfulResponseHandler](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpUnsuccessfulResponseHandler)s.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.collections.generic.ilist-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpUnsuccessfulResponseHandler` |   |

## Methods

### AddExceptionHandler(IHttpExceptionHandler)

    public void AddExceptionHandler(IHttpExceptionHandler handler)

Adds the specified handler to the list of exception handlers.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `handler` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpExceptionHandler` |

### AddExecuteInterceptor(IHttpExecuteInterceptor)

    public void AddExecuteInterceptor(IHttpExecuteInterceptor interceptor)

Adds the specified interceptor to the list of execute interceptors.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `interceptor` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpExecuteInterceptor` |

### AddUnsuccessfulResponseHandler(IHttpUnsuccessfulResponseHandler)

    public void AddUnsuccessfulResponseHandler(IHttpUnsuccessfulResponseHandler handler)

Adds the specified handler to the list of unsuccessful response handlers.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `handler` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpUnsuccessfulResponseHandler` |

### RemoveExceptionHandler(IHttpExceptionHandler)

    public void RemoveExceptionHandler(IHttpExceptionHandler handler)

Removes the specified handler from the list of exception handlers.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `handler` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpExceptionHandler` |

### RemoveExecuteInterceptor(IHttpExecuteInterceptor)

    public void RemoveExecuteInterceptor(IHttpExecuteInterceptor interceptor)

Removes the specified interceptor from the list of execute interceptors.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `interceptor` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpExecuteInterceptor` |

### RemoveUnsuccessfulResponseHandler(IHttpUnsuccessfulResponseHandler)

    public void RemoveUnsuccessfulResponseHandler(IHttpUnsuccessfulResponseHandler handler)

Removes the specified handler from the list of unsuccessful response handlers.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `handler` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.IHttpUnsuccessfulResponseHandler` |

### SendAsync(HttpRequestMessage, CancellationToken)

    protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)

The main logic of sending a request to the server. This send method adds the User-Agent header to a request
with [ApplicationName](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Http.ConfigurableMessageHandler#Google_Apis_Http_ConfigurableMessageHandler_ApplicationName) and the library version. It also calls interceptors before each attempt,
and unsuccessful response handler or exception handlers when abnormal response or exception occurred.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://learn.microsoft.com/dotnet/api/system.net.http.httprequestmessage` |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://learn.microsoft.com/dotnet/api/system.net.http.httpresponsemessage` |   |

**Overrides** [DelegatingHandler.SendAsync(HttpRequestMessage, CancellationToken)](https://learn.microsoft.com/dotnet/api/system.net.http.delegatinghandler.sendasync)

## Extension Method

[Utilities.ThrowIfNull\<T\>(T, string)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Util.Utilities#Google_Apis_Util_Utilities_ThrowIfNull__1___0_System_String_)