Class ConfigurableMessageHandler (1.59.0)

public class ConfigurableMessageHandler : DelegatingHandler, IDisposable

A message handler which contains the main logic of our HTTP requests. It contains a list of IHttpUnsuccessfulResponseHandlers for handling abnormal responses, a list of IHttpExceptionHandlers for handling exception in a request and a list of IHttpExecuteInterceptors 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 > HttpMessageHandler > DelegatingHandler > ConfigurableMessageHandler

Implements

IDisposable

Namespace

Google.Apis.Http

Assembly

Google.Apis.Core.dll

Constructors

ConfigurableMessageHandler(HttpMessageHandler)

public ConfigurableMessageHandler(HttpMessageHandler httpMessageHandler)

Constructs a new configurable message handler.

Parameter
NameDescription
httpMessageHandlerHttpMessageHandler

Fields

CredentialKey

public const string CredentialKey = "__CredentialKey"

Key for a credential in a HttpRequestMessage properties.

Field Value
TypeDescription
String

ExceptionHandlerKey

public const string ExceptionHandlerKey = "__ExceptionHandlerKey"

Key for exception handlers in an HttpRequestMessage properties.

Field Value
TypeDescription
String

ExecuteInterceptorKey

public const string ExecuteInterceptorKey = "__ExecuteInterceptorKey"

Key for execute handlers in an HttpRequestMessage properties.

Field Value
TypeDescription
String

MaxAllowedNumTries

public const int MaxAllowedNumTries = 20

Maximum allowed number of tries.

Field Value
TypeDescription
Int32

MaxRetriesKey

public const string MaxRetriesKey = "__MaxRetriesKey"

Key for request specific max retries.

Field Value
TypeDescription
String

ResponseStreamInterceptorProviderKey

public const string ResponseStreamInterceptorProviderKey = "__ResponseStreamInterceptorProviderKey"

Key for a stream response interceptor provider in an HttpRequestMessage properties.

Field Value
TypeDescription
String

UnsuccessfulResponseHandlerKey

public const string UnsuccessfulResponseHandlerKey = "__UnsuccessfulResponseHandlerKey"

Key for unsuccessful response handlers in an HttpRequestMessage properties.

Field Value
TypeDescription
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
TypeDescription
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 implements IHttpUnsuccessfulResponseHandler then it will also be included as a handler of an unsuccessful response.

Property Value
TypeDescription
IHttpExecuteInterceptor

ExceptionHandlers

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

Gets a list of IHttpExceptionHandlers.

Property Value
TypeDescription
IList<IHttpExceptionHandler>

ExecuteInterceptors

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

Gets a list of IHttpExecuteInterceptors.

Property Value
TypeDescription
IList<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
TypeDescription
Boolean

GoogleApiClientHeader

public string GoogleApiClientHeader { get; set; }

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

Property Value
TypeDescription
String

IsLoggingEnabled

public bool IsLoggingEnabled { get; set; }

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

Property Value
TypeDescription
Boolean

LogEvents

public ConfigurableMessageHandler.LogEventType LogEvents { get; set; }

The request/response types to log.

Property Value
TypeDescription
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 for more information.

Property Value
TypeDescription
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 or 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
TypeDescription
Int32

UnsuccessfulResponseHandlers

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

Methods

AddExceptionHandler(IHttpExceptionHandler)

public void AddExceptionHandler(IHttpExceptionHandler handler)

Adds the specified handler to the list of exception handlers.

Parameter
NameDescription
handlerIHttpExceptionHandler

AddExecuteInterceptor(IHttpExecuteInterceptor)

public void AddExecuteInterceptor(IHttpExecuteInterceptor interceptor)

Adds the specified interceptor to the list of execute interceptors.

Parameter
NameDescription
interceptorIHttpExecuteInterceptor

AddUnsuccessfulResponseHandler(IHttpUnsuccessfulResponseHandler)

public void AddUnsuccessfulResponseHandler(IHttpUnsuccessfulResponseHandler handler)

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

Parameter
NameDescription
handlerIHttpUnsuccessfulResponseHandler

RemoveExceptionHandler(IHttpExceptionHandler)

public void RemoveExceptionHandler(IHttpExceptionHandler handler)

Removes the specified handler from the list of exception handlers.

Parameter
NameDescription
handlerIHttpExceptionHandler

RemoveExecuteInterceptor(IHttpExecuteInterceptor)

public void RemoveExecuteInterceptor(IHttpExecuteInterceptor interceptor)

Removes the specified interceptor from the list of execute interceptors.

Parameter
NameDescription
interceptorIHttpExecuteInterceptor

RemoveUnsuccessfulResponseHandler(IHttpUnsuccessfulResponseHandler)

public void RemoveUnsuccessfulResponseHandler(IHttpUnsuccessfulResponseHandler handler)

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

Parameter
NameDescription
handlerIHttpUnsuccessfulResponseHandler

SendAsync(HttpRequestMessage, CancellationToken)

protected override async 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 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
NameDescription
requestHttpRequestMessage
cancellationTokenCancellationToken
Returns
TypeDescription
Task<HttpResponseMessage>
Overrides

Extension Method