Class ConfigurableMessageHandler (1.68.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
Name Description
httpMessageHandler HttpMessageHandler

Fields

CredentialKey

public const string CredentialKey = "__CredentialKey"

Key for a credential in a HttpRequestMessage options.

Field Value
Type Description
string

ExceptionHandlerKey

public const string ExceptionHandlerKey = "__ExceptionHandlerKey"

Key for exception handlers in an HttpRequestMessage options.

Field Value
Type Description
string

ExecuteInterceptorKey

public const string ExecuteInterceptorKey = "__ExecuteInterceptorKey"

Key for execute handlers in an HttpRequestMessage options.

Field Value
Type Description
string

MaxAllowedNumTries

public const int MaxAllowedNumTries = 20

Maximum allowed number of tries.

Field Value
Type Description
int

MaxRetriesKey

public const string MaxRetriesKey = "__MaxRetriesKey"

Key for request specific max retries.

Field Value
Type Description
string

ResponseStreamInterceptorProviderKey

public const string ResponseStreamInterceptorProviderKey = "__ResponseStreamInterceptorProviderKey"

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

Field Value
Type Description
string

UnsuccessfulResponseHandlerKey

public const string UnsuccessfulResponseHandlerKey = "__UnsuccessfulResponseHandlerKey"

Key for unsuccessful response handlers in an HttpRequestMessage options.

Field Value
Type Description
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
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
Type Description
IHttpExecuteInterceptor

ExceptionHandlers

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

Gets a list of IHttpExceptionHandlers.

Property Value
Type Description
IListIHttpExceptionHandler

ExecuteInterceptors

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

Gets a list of IHttpExecuteInterceptors.

Property Value
Type Description
IListIHttpExecuteInterceptor

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
bool

GoogleApiClientHeader

public string GoogleApiClientHeader { get; set; }

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

Property Value
Type Description
string

IsLoggingEnabled

public bool IsLoggingEnabled { get; set; }

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

Property Value
Type Description
bool

LogEvents

public ConfigurableMessageHandler.LogEventType LogEvents { get; set; }

The request/response types to log.

Property Value
Type Description
ConfigurableMessageHandlerLogEventType

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
Type Description
int

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
Type Description
int

UniverseDomain

public string UniverseDomain { get; set; }

The universe domain to include as an option in the request. This may be used by the 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
string

UnsuccessfulResponseHandlers

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

Methods

AddExceptionHandler(IHttpExceptionHandler)

public void AddExceptionHandler(IHttpExceptionHandler handler)

Adds the specified handler to the list of exception handlers.

Parameter
Name Description
handler IHttpExceptionHandler

AddExecuteInterceptor(IHttpExecuteInterceptor)

public void AddExecuteInterceptor(IHttpExecuteInterceptor interceptor)

Adds the specified interceptor to the list of execute interceptors.

Parameter
Name Description
interceptor IHttpExecuteInterceptor

AddUnsuccessfulResponseHandler(IHttpUnsuccessfulResponseHandler)

public void AddUnsuccessfulResponseHandler(IHttpUnsuccessfulResponseHandler handler)

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

Parameter
Name Description
handler IHttpUnsuccessfulResponseHandler

RemoveExceptionHandler(IHttpExceptionHandler)

public void RemoveExceptionHandler(IHttpExceptionHandler handler)

Removes the specified handler from the list of exception handlers.

Parameter
Name Description
handler IHttpExceptionHandler

RemoveExecuteInterceptor(IHttpExecuteInterceptor)

public void RemoveExecuteInterceptor(IHttpExecuteInterceptor interceptor)

Removes the specified interceptor from the list of execute interceptors.

Parameter
Name Description
interceptor IHttpExecuteInterceptor

RemoveUnsuccessfulResponseHandler(IHttpUnsuccessfulResponseHandler)

public void RemoveUnsuccessfulResponseHandler(IHttpUnsuccessfulResponseHandler handler)

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

Parameter
Name Description
handler 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 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 HttpRequestMessage
cancellationToken CancellationToken
Returns
Type Description
TaskHttpResponseMessage
Overrides

Extension Method