Class ConfigurableMessageHandler

public class ConfigurableMessageHandler : DelegatingHandler

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 > ConfigurableMessageHandler

Namespace

Google.Apis.Http

Assembly

Google.Apis.Core.dll

Constructors

ConfigurableMessageHandler(HttpMessageHandler)

public ConfigurableMessageHandler(HttpMessageHandler httpMessageHandler)

Constructs a new configurable message handler.

Parameter
TypeNameDescription
HttpMessageHandlerhttpMessageHandler

Fields

CredentialKey

public const string CredentialKey = null

Key for a credential in a properties.

Field Value
TypeDescription
String

ExceptionHandlerKey

public const string ExceptionHandlerKey = null

Key for exception handlers in an properties.

Field Value
TypeDescription
String

ExecuteInterceptorKey

public const string ExecuteInterceptorKey = null

Key for execute handlers in an properties.

Field Value
TypeDescription
String

MaxAllowedNumTries

public const int MaxAllowedNumTries = null

Maximum allowed number of tries.

Field Value
TypeDescription
Int32

ResponseStreamInterceptorProviderKey

public const string ResponseStreamInterceptorProviderKey = null

Key for a stream response interceptor provider in an properties.

Field Value
TypeDescription
String

UnsuccessfulResponseHandlerKey

public const string UnsuccessfulResponseHandlerKey = null

Key for unsuccessful response handlers in an 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

public IList<IHttpExceptionHandler> ExceptionHandlers { get; }

Gets a list of IHttpExceptionHandlers.

Property Value
TypeDescription
IList<IHttpExceptionHandler>

ExecuteInterceptors

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

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
TypeNameDescription
IHttpExceptionHandlerhandler

AddExecuteInterceptor(IHttpExecuteInterceptor)

public void AddExecuteInterceptor(IHttpExecuteInterceptor interceptor)

Adds the specified interceptor to the list of execute interceptors.

Parameter
TypeNameDescription
IHttpExecuteInterceptorinterceptor

AddUnsuccessfulResponseHandler(IHttpUnsuccessfulResponseHandler)

public void AddUnsuccessfulResponseHandler(IHttpUnsuccessfulResponseHandler handler)

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

Parameter
TypeNameDescription
IHttpUnsuccessfulResponseHandlerhandler

RemoveExceptionHandler(IHttpExceptionHandler)

public void RemoveExceptionHandler(IHttpExceptionHandler handler)

Removes the specified handler from the list of exception handlers.

Parameter
TypeNameDescription
IHttpExceptionHandlerhandler

RemoveExecuteInterceptor(IHttpExecuteInterceptor)

public void RemoveExecuteInterceptor(IHttpExecuteInterceptor interceptor)

Removes the specified interceptor from the list of execute interceptors.

Parameter
TypeNameDescription
IHttpExecuteInterceptorinterceptor

RemoveUnsuccessfulResponseHandler(IHttpUnsuccessfulResponseHandler)

public void RemoveUnsuccessfulResponseHandler(IHttpUnsuccessfulResponseHandler handler)

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

Parameter
TypeNameDescription
IHttpUnsuccessfulResponseHandlerhandler

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 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
TypeNameDescription
HttpRequestMessagerequest
CancellationTokencancellationToken
Returns
TypeDescription
Task<HttpResponseMessage>

Extension Method