Show / Hide Table of Contents

Class ConfigurableMessageHandler

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
System.Object
System.Net.Http.HttpMessageHandler
System.Net.Http.DelegatingHandler
ConfigurableMessageHandler
Implements
System.IDisposable
Inherited Members
System.Net.Http.DelegatingHandler.Dispose(System.Boolean)
System.Net.Http.DelegatingHandler.InnerHandler
System.Net.Http.HttpMessageHandler.Dispose()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Google.Apis.Http
Assembly: Google.Apis.Core.dll
Syntax
public class ConfigurableMessageHandler : DelegatingHandler, IDisposable

Constructors

ConfigurableMessageHandler(HttpMessageHandler)

Constructs a new configurable message handler.

Declaration
public ConfigurableMessageHandler(HttpMessageHandler httpMessageHandler)
Parameters
Type Name Description
System.Net.Http.HttpMessageHandler httpMessageHandler

Fields

CredentialKey

Key for a credential in a System.Net.Http.HttpRequestMessage properties.

Declaration
public const string CredentialKey = "__CredentialKey"
Field Value
Type Description
System.String

ExceptionHandlerKey

Key for exception handlers in an System.Net.Http.HttpRequestMessage properties.

Declaration
public const string ExceptionHandlerKey = "__ExceptionHandlerKey"
Field Value
Type Description
System.String

ExecuteInterceptorKey

Key for execute handlers in an System.Net.Http.HttpRequestMessage properties.

Declaration
public const string ExecuteInterceptorKey = "__ExecuteInterceptorKey"
Field Value
Type Description
System.String

MaxAllowedNumTries

Maximum allowed number of tries.

Declaration
public const int MaxAllowedNumTries = 20
Field Value
Type Description
System.Int32

ResponseStreamInterceptorProviderKey

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

Declaration
public const string ResponseStreamInterceptorProviderKey = "__ResponseStreamInterceptorProviderKey"
Field Value
Type Description
System.String

UnsuccessfulResponseHandlerKey

Key for unsuccessful response handlers in an System.Net.Http.HttpRequestMessage properties.

Declaration
public const string UnsuccessfulResponseHandlerKey = "__UnsuccessfulResponseHandlerKey"
Field Value
Type Description
System.String

Properties

ApplicationName

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

Declaration
public string ApplicationName { get; set; }
Property Value
Type Description
System.String

Credential

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.

Declaration
public IHttpExecuteInterceptor Credential { get; set; }
Property Value
Type Description
IHttpExecuteInterceptor

ExceptionHandlers

Gets a list of IHttpExceptionHandlers. Since version 1.10, AddExceptionHandler(IHttpExceptionHandler) and RemoveExceptionHandler(IHttpExceptionHandler) were added in order to keep this class thread-safe. More information is available on #592.

Declaration
[Obsolete("Use AddExceptionHandler or RemoveExceptionHandler instead.")]
public IList<IHttpExceptionHandler> ExceptionHandlers { get; }
Property Value
Type Description
System.Collections.Generic.IList<IHttpExceptionHandler>

ExecuteInterceptors

Gets a list of IHttpExecuteInterceptors. Since version 1.10, AddExecuteInterceptor(IHttpExecuteInterceptor) and RemoveExecuteInterceptor(IHttpExecuteInterceptor) were added in order to keep this class thread-safe. More information is available on #592.

Declaration
[Obsolete("Use AddExecuteInterceptor or RemoveExecuteInterceptor instead.")]
public IList<IHttpExecuteInterceptor> ExecuteInterceptors { get; }
Property Value
Type Description
System.Collections.Generic.IList<IHttpExecuteInterceptor>

FollowRedirect

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

Declaration
public bool FollowRedirect { get; set; }
Property Value
Type Description
System.Boolean

GoogleApiClientHeader

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

Declaration
public string GoogleApiClientHeader { get; set; }
Property Value
Type Description
System.String

IsLoggingEnabled

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

Declaration
public bool IsLoggingEnabled { get; set; }
Property Value
Type Description
System.Boolean

LogEvents

The request/response types to log.

Declaration
public ConfigurableMessageHandler.LogEventType LogEvents { get; set; }
Property Value
Type Description
ConfigurableMessageHandler.LogEventType

NumRedirects

Gets or sets the number of redirects that will be allowed to execute. The default value is 10. See NumTries for more information.

Declaration
public int NumRedirects { get; set; }
Property Value
Type Description
System.Int32

NumTries

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. The number of allowed redirects (3xx) is defined by NumRedirects. This property defines only the allowed tries for >=400 responses, or when an exception is thrown. For example if you set NumTries to 1 and NumRedirects to 5, the library will send up to five redirect requests, but will not send any retry requests due to an error HTTP status code.

Declaration
public int NumTries { get; set; }
Property Value
Type Description
System.Int32

UnsuccessfulResponseHandlers

Gets a list of IHttpUnsuccessfulResponseHandlers. Since version 1.10, AddUnsuccessfulResponseHandler(IHttpUnsuccessfulResponseHandler) and RemoveUnsuccessfulResponseHandler(IHttpUnsuccessfulResponseHandler) were added in order to keep this class thread-safe. More information is available on #592.

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

Methods

AddExceptionHandler(IHttpExceptionHandler)

Adds the specified handler to the list of exception handlers.

Declaration
public void AddExceptionHandler(IHttpExceptionHandler handler)
Parameters
Type Name Description
IHttpExceptionHandler handler

AddExecuteInterceptor(IHttpExecuteInterceptor)

Adds the specified interceptor to the list of execute interceptors.

Declaration
public void AddExecuteInterceptor(IHttpExecuteInterceptor interceptor)
Parameters
Type Name Description
IHttpExecuteInterceptor interceptor

AddUnsuccessfulResponseHandler(IHttpUnsuccessfulResponseHandler)

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

Declaration
public void AddUnsuccessfulResponseHandler(IHttpUnsuccessfulResponseHandler handler)
Parameters
Type Name Description
IHttpUnsuccessfulResponseHandler handler

RemoveExceptionHandler(IHttpExceptionHandler)

Removes the specified handler from the list of exception handlers.

Declaration
public void RemoveExceptionHandler(IHttpExceptionHandler handler)
Parameters
Type Name Description
IHttpExceptionHandler handler

RemoveExecuteInterceptor(IHttpExecuteInterceptor)

Removes the specified interceptor from the list of execute interceptors.

Declaration
public void RemoveExecuteInterceptor(IHttpExecuteInterceptor interceptor)
Parameters
Type Name Description
IHttpExecuteInterceptor interceptor

RemoveUnsuccessfulResponseHandler(IHttpUnsuccessfulResponseHandler)

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

Declaration
public void RemoveUnsuccessfulResponseHandler(IHttpUnsuccessfulResponseHandler handler)
Parameters
Type Name Description
IHttpUnsuccessfulResponseHandler handler

SendAsync(HttpRequestMessage, 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.

Declaration
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
Parameters
Type Name Description
System.Net.Http.HttpRequestMessage request
System.Threading.CancellationToken cancellationToken
Returns
Type Description
System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage>
Overrides
System.Net.Http.DelegatingHandler.SendAsync(System.Net.Http.HttpRequestMessage, System.Threading.CancellationToken)

Implements

System.IDisposable

Extension Methods

Utilities.ThrowIfNull<T>(T, String)
In This Article
Back to top