using System; using System.Collections.Generic; using System.Net.Http; using System.Text; namespace LaunchDarkly.EventSource { /// /// An immutable class containing configuration properties for . /// /// /// public sealed class Configuration { #region Constants /// /// The default value for : /// one second. /// public static readonly TimeSpan DefaultInitialRetryDelay = TimeSpan.FromSeconds(1); /// /// The default value for : /// 30 seconds. /// public static readonly TimeSpan DefaultMaxRetryDelay = TimeSpan.FromSeconds(30); /// /// The default value for : /// 10 seconds. /// public static readonly TimeSpan DefaultResponseStartTimeout = TimeSpan.FromSeconds(10); /// /// Obsolete name for . /// [Obsolete("Use DefaultResponseStartTimeout")] public static readonly TimeSpan DefaultConnectionTimeout = DefaultResponseStartTimeout; /// /// The default value for : /// 5 minutes. /// public static readonly TimeSpan DefaultReadTimeout = TimeSpan.FromMinutes(5); /// /// The default value for : /// one minute. /// public static readonly TimeSpan DefaultBackoffResetThreshold = TimeSpan.FromMinutes(1); /// /// The logger name that will be used if you specified a logging implementation but did not /// provide a specific logger instance. /// /// public const string DefaultLoggerName = "EventSource"; #endregion #region Public Properties /// /// The amount of time a connection must stay open before the EventSource resets its backoff delay. /// /// /// A connection that stays open for at least this long also discards any temporary bounds set /// by . /// /// public TimeSpan BackoffResetThreshold { get; } /// /// Obsolete name for . /// [Obsolete("Use ResponseStartTimeout")] public TimeSpan ConnectionTimeout => ResponseStartTimeout; /// /// The HttpClient that will be used as the HTTP client, or null for a new HttpClient. /// /// public HttpClient HttpClient { get; } /// /// The HttpMessageHandler that will be used for the HTTP client, or null for the default handler. /// /// public HttpMessageHandler HttpMessageHandler { get; } /// /// Delegate hook invoked before an HTTP request has been performed. /// /// public Action HttpRequestModifier { get; } /// /// The initial amount of time to wait before attempting to reconnect to the EventSource API. /// /// public TimeSpan InitialRetryDelay { get; } /// /// Gets the last event identifier. /// /// public string LastEventId { get; } /// /// The logger to be used for all EventSource log output. /// /// /// This is never null; if logging is not configured, it will be LaunchDarkly.Logging.Logs.None. /// /// /// /// The maximum amount of time to wait before attempting to reconnect. /// /// public TimeSpan MaxRetryDelay { get; } /// /// The HTTP method that will be used when connecting to the EventSource API. /// /// public HttpMethod Method { get; } /// /// Whether to use UTF-8 byte arrays internally if possible when reading the stream. /// /// public bool PreferDataAsUtf8Bytes { get; } /// /// The timeout when reading from the EventSource API. /// /// public TimeSpan ReadTimeout { get; } /// /// A factory for HTTP request body content, if the HTTP method is one that allows a request body. /// is one that allows a request body. This is in the form of a factory function because the request /// may need to be sent more than once. /// /// public Func RequestBodyFactory { get; } /// /// The request headers to be sent with each EventSource HTTP request. /// /// /// public IDictionary RequestHeaders { get; } /// /// The maximum amount of time to wait between starting an HTTP request and receiving the response /// headers. /// /// public TimeSpan ResponseStartTimeout { get; } /// /// Gets the used when connecting to an EventSource API. /// public Uri Uri { get; } #endregion #region Internal Constructor internal Configuration(ConfigurationBuilder builder) { Uri = builder._uri; BackoffResetThreshold = builder._backoffResetThreshold; HttpClient = builder._httpClient; HttpMessageHandler = (builder._httpClient != null) ? null : builder._httpMessageHandler; InitialRetryDelay = builder._initialRetryDelay; LastEventId = builder._lastEventId; MaxRetryDelay = builder._maxRetryDelay; Method = builder._method; PreferDataAsUtf8Bytes = builder._preferDataAsUtf8Bytes; ReadTimeout = builder._readTimeout; RequestHeaders = new Dictionary(builder._requestHeaders); ResponseStartTimeout = builder._responseStartTimeout; RequestBodyFactory = builder._requestBodyFactory; HttpRequestModifier = builder._httpRequestModifier; } #endregion #region Public Methods /// /// Provides a new for constructing a configuration. /// /// the EventSource URI /// a new builder instance /// if the URI is null public static ConfigurationBuilder Builder(Uri uri) => new ConfigurationBuilder(uri); #endregion } }