/// <summary> /// Initializes a new instance of the <see cref="ElasticConnectionImpl"/> class. /// Create a new ElasticConnectionImpl with the given parameters defining its properties. /// </summary> /// <param name="endpoint"> /// The URL endpoint of the Elasticsearch server. /// </param> /// <param name="userName"> /// UserName to use to connect to the server (optional). /// </param> /// <param name="password"> /// Password to use to connect to the server (optional). /// </param> /// <param name="timeout"> /// TimeSpan to wait for network responses before failing (optional, defaults to 10 seconds). /// </param> /// <param name="index"> /// Name of the index to use on the server (optional). /// </param> /// <param name="options"> /// Additional options that specify how this connection should behave. /// </param> public ElasticConnectionImpl(Uri endpoint, string userName = null, string password = null, TimeSpan?timeout = null, string index = null, ElasticConnectionOptions options = null) : this(new HttpClientHandler(), endpoint, userName, password, index, timeout, options) { }
/// <summary> /// Initializes a new instance of the <see cref="ElasticConnectionImpl"/> class. /// Create a new ElasticConnectionImpl with the given parameters for internal testing. /// </summary> /// <param name="innerMessageHandler"> /// The HttpMessageHandler used to intercept network requests for testing. /// </param> /// <param name="endpoint"> /// The URL endpoint of the Elasticsearch server. /// </param> /// <param name="userName"> /// UserName to use to connect to the server (optional). /// </param> /// <param name="password"> /// Password to use to connect to the server (optional). /// </param> /// <param name="index"> /// Name of the index to use on the server (optional). /// </param> /// <param name="timeout"> /// TimeSpan to wait for network responses before failing (optional, defaults to 10 seconds). /// </param> /// <param name="options"> /// Additional options that specify how this connection should behave. /// </param> internal ElasticConnectionImpl(HttpMessageHandler innerMessageHandler, Uri endpoint, string userName = null, string password = null, string index = null, TimeSpan?timeout = null, ElasticConnectionOptions options = null) : base(endpoint, index, timeout, options) { var httpClientHandler = innerMessageHandler as HttpClientHandler; if (httpClientHandler != null && httpClientHandler.SupportsAutomaticDecompression) { httpClientHandler.AutomaticDecompression = DecompressionMethods.GZip; } HttpClient = new HttpClient(new ForcedAuthHandler(userName, password, innerMessageHandler), true); }
/// <summary> /// Initializes a new instance of the <see cref="ElasticConnectionBase"/> class. /// Create a new ElasticConnectionBase with the given parameters for internal testing. /// </summary> /// <param name="endpoint"> /// The endpoint. /// </param> /// <param name="index"> /// Name of the index to use on the server (optional). /// </param> /// <param name="timeout"> /// TimeSpan to wait for network responses before failing (optional, defaults to 10 seconds). /// </param> /// <param name="options"> /// Additional options that specify how this connection should behave. /// </param> protected ElasticConnectionBase(Uri endpoint, string index = null, TimeSpan?timeout = null, ElasticConnectionOptions options = null) { if (timeout.HasValue) { Argument.CheckPositive("value", timeout.Value); } if (index != null) { Argument.CheckNotEmpty("index", index); } Argument.CheckNotNull("endpoint", endpoint); this.Endpoint = endpoint; this.Index = index; this.Options = options ?? new ElasticConnectionOptions(); this.Timeout = timeout ?? DefaultTimeout; }