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
object
HttpMessageHandler
DelegatingHandler
ConfigurableMessageHandler
Implements
IDisposable
Inherited Members
DelegatingHandler.Dispose(bool)
DelegatingHandler.InnerHandler
HttpMessageHandler.Dispose()
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
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
HttpMessageHandler httpMessageHandler

Fields

CredentialKey

Key for a credential in a HttpRequestMessage options.

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

ExceptionHandlerKey

Key for exception handlers in an HttpRequestMessage options.

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

ExecuteInterceptorKey

Key for execute handlers in an HttpRequestMessage options.

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

MaxAllowedNumTries

Maximum allowed number of tries.

Declaration
public const int MaxAllowedNumTries = 20
Field Value
Type Description
int

MaxRetriesKey

Key for request specific max retries.

Declaration
public const string MaxRetriesKey = "__MaxRetriesKey"
Field Value
Type Description
string

ResponseStreamInterceptorProviderKey

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

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

UnsuccessfulResponseHandlerKey

Key for unsuccessful response handlers in an HttpRequestMessage options.

Declaration
public const string UnsuccessfulResponseHandlerKey = "__UnsuccessfulResponseHandlerKey"
Field Value
Type Description
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
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
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
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
bool

GoogleApiClientHeader

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

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

IsLoggingEnabled

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

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

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
int

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
int

UniverseDomain

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.

Declaration
public string UniverseDomain { get; set; }
Property Value
Type Description
string

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
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 Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
Parameters
Type Name Description
HttpRequestMessage request
CancellationToken cancellationToken
Returns
Type Description
Task<HttpResponseMessage>
Overrides
DelegatingHandler.SendAsync(HttpRequestMessage, CancellationToken)

Implements

IDisposable

Extension Methods

Utilities.ThrowIfNull<T>(T, string)
In this article
Back to top Generated by DocFX