|
7 | 7 | using System.Diagnostics.CodeAnalysis;
|
8 | 8 | using System.Net.Http;
|
9 | 9 | using System.Net.Security;
|
| 10 | +using System.Reflection; |
10 | 11 | using System.Security;
|
11 | 12 | using System.Security.Cryptography.X509Certificates;
|
12 | 13 | using System.Threading;
|
13 |
| -using Elasticsearch.Net.CrossPlatform; |
| 14 | +using System.Runtime.InteropServices; |
14 | 15 | using Elasticsearch.Net.Extensions;
|
15 | 16 |
|
16 | 17 | namespace Elasticsearch.Net
|
17 | 18 | {
|
18 | 19 | /// <summary>
|
19 |
| - /// ConnectionConfiguration allows you to control how ElasticLowLevelClient behaves and where/how it connects |
20 |
| - /// to elasticsearch |
| 20 | + /// Allows you to control how <see cref="ElasticLowLevelClient"/> behaves and where/how it connects to Elasticsearch |
21 | 21 | /// </summary>
|
22 | 22 | public class ConnectionConfiguration : ConnectionConfiguration<ConnectionConfiguration>
|
23 | 23 | {
|
24 |
| - private static bool IsCurlHandler { get; } = typeof(HttpClientHandler).Assembly().GetType("System.Net.Http.CurlHandler") != null; |
| 24 | + private static bool IsCurlHandler { get; } = typeof(HttpClientHandler).Assembly.GetType("System.Net.Http.CurlHandler") != null; |
25 | 25 |
|
| 26 | + /// <summary> |
| 27 | + /// The default ping timeout. Defaults to 2 seconds |
| 28 | + /// </summary> |
26 | 29 | public static readonly TimeSpan DefaultPingTimeout = TimeSpan.FromSeconds(2);
|
| 30 | + |
| 31 | + /// <summary> |
| 32 | + /// The default ping timeout when the connection is over HTTPS. Defaults to |
| 33 | + /// 5 seconds |
| 34 | + /// </summary> |
27 | 35 | public static readonly TimeSpan DefaultPingTimeoutOnSSL = TimeSpan.FromSeconds(5);
|
| 36 | + |
| 37 | + /// <summary> |
| 38 | + /// The default timeout before the client aborts a request to Elasticsearch. |
| 39 | + /// Defaults to 1 minute |
| 40 | + /// </summary> |
28 | 41 | public static readonly TimeSpan DefaultTimeout = TimeSpan.FromMinutes(1);
|
| 42 | + |
| 43 | + /// <summary> |
| 44 | + /// The default connection limit for both Elasticsearch.Net and Nest. Defaults to <c>80</c> except for |
| 45 | + /// <see cref="HttpClientHandler"/> implementations based on curl, which defaults to |
| 46 | + /// <see cref="Environment.ProcessorCount"/> |
| 47 | + /// </summary> |
29 | 48 | public static readonly int DefaultConnectionLimit = IsCurlHandler ? Environment.ProcessorCount : 80;
|
30 | 49 |
|
| 50 | + /// <summary> |
| 51 | + /// The default user agent for Elasticsearch.Net |
| 52 | + /// </summary> |
| 53 | + public static readonly string DefaultUserAgent = $"elasticsearch-net/{typeof(IConnectionConfigurationValues).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion} ({RuntimeInformation.OSDescription}; {RuntimeInformation.FrameworkDescription}; Elasticsearch.Net)"; |
31 | 54 |
|
32 | 55 | /// <summary>
|
33 |
| - /// ConnectionConfiguration allows you to control how ElasticLowLevelClient behaves and where/how it connects |
34 |
| - /// to elasticsearch |
| 56 | + /// Creates a new instance of <see cref="ConnectionConfiguration"/> |
35 | 57 | /// </summary>
|
36 |
| - /// <param name="uri">The root of the elasticsearch node we want to connect to. Defaults to http://localhost:9200</param> |
| 58 | + /// <param name="uri">The root of the Elasticsearch node we want to connect to. Defaults to http://localhost:9200</param> |
37 | 59 | [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
|
38 | 60 | public ConnectionConfiguration(Uri uri = null)
|
39 | 61 | : this(new SingleNodeConnectionPool(uri ?? new Uri("http://localhost:9200"))) { }
|
40 | 62 |
|
41 | 63 | /// <summary>
|
42 |
| - /// ConnectionConfiguration allows you to control how ElasticLowLevelClient behaves and where/how it connects |
43 |
| - /// to elasticsearch |
| 64 | + /// Creates a new instance of <see cref="ConnectionConfiguration"/> |
44 | 65 | /// </summary>
|
45 |
| - /// <param name="connectionPool">A connection pool implementation that'll tell the client what nodes are available</param> |
| 66 | + /// <param name="connectionPool">A connection pool implementation that tells the client what nodes are available</param> |
46 | 67 | public ConnectionConfiguration(IConnectionPool connectionPool)
|
47 | 68 | // ReSharper disable once IntroduceOptionalParameters.Global
|
48 | 69 | : this(connectionPool, null, null) { }
|
49 | 70 |
|
| 71 | + /// <summary> |
| 72 | + /// Creates a new instance of <see cref="ConnectionConfiguration"/> |
| 73 | + /// </summary> |
| 74 | + /// <param name="connectionPool">A connection pool implementation that tells the client what nodes are available</param> |
| 75 | + /// <param name="connection">An connection implementation that can make API requests</param> |
50 | 76 | public ConnectionConfiguration(IConnectionPool connectionPool, IConnection connection)
|
51 | 77 | // ReSharper disable once IntroduceOptionalParameters.Global
|
52 | 78 | : this(connectionPool, connection, null) { }
|
53 | 79 |
|
| 80 | + /// <summary> |
| 81 | + /// Creates a new instance of <see cref="ConnectionConfiguration"/> |
| 82 | + /// </summary> |
| 83 | + /// <param name="connectionPool">A connection pool implementation that tells the client what nodes are available</param> |
| 84 | + /// <param name="serializer">A serializer implementation used to serialize requests and deserialize responses</param> |
54 | 85 | public ConnectionConfiguration(IConnectionPool connectionPool, IElasticsearchSerializer serializer)
|
55 | 86 | : this(connectionPool, null, serializer) { }
|
56 | 87 |
|
57 |
| - // ReSharper disable once MemberCanBePrivate.Global |
58 |
| - // eventhough we use don't use this we very much would like to expose this constructor |
59 |
| - |
| 88 | + /// <summary> |
| 89 | + /// Creates a new instance of <see cref="ConnectionConfiguration"/> |
| 90 | + /// </summary> |
| 91 | + /// <param name="connectionPool">A connection pool implementation that tells the client what nodes are available</param> |
| 92 | + /// <param name="connection">An connection implementation that can make API requests</param> |
| 93 | + /// <param name="serializer">A serializer implementation used to serialize requests and deserialize responses</param> |
60 | 94 | public ConnectionConfiguration(IConnectionPool connectionPool, IConnection connection, IElasticsearchSerializer serializer)
|
61 | 95 | : base(connectionPool, connection, serializer) { }
|
62 | 96 |
|
@@ -104,6 +138,8 @@ public abstract class ConnectionConfiguration<T> : IConnectionConfigurationValue
|
104 | 138 | private bool _sniffOnStartup;
|
105 | 139 | private bool _throwExceptions;
|
106 | 140 |
|
| 141 | + private string _userAgent = ConnectionConfiguration.DefaultUserAgent; |
| 142 | + |
107 | 143 | protected ConnectionConfiguration(IConnectionPool connectionPool, IConnection connection, IElasticsearchSerializer requestResponseSerializer)
|
108 | 144 | {
|
109 | 145 | _connectionPool = connectionPool;
|
@@ -163,6 +199,7 @@ protected ConnectionConfiguration(IConnectionPool connectionPool, IConnection co
|
163 | 199 | bool IConnectionConfigurationValues.SniffsOnStartup => _sniffOnStartup;
|
164 | 200 | bool IConnectionConfigurationValues.ThrowExceptions => _throwExceptions;
|
165 | 201 | ElasticsearchUrlFormatter IConnectionConfigurationValues.UrlFormatter => _urlFormatter;
|
| 202 | + string IConnectionConfigurationValues.UserAgent => _userAgent; |
166 | 203 |
|
167 | 204 | void IDisposable.Dispose() => DisposeManagedResources();
|
168 | 205 |
|
@@ -463,6 +500,12 @@ public T ClientCertificate(string certificatePath) =>
|
463 | 500 | public T SkipDeserializationForStatusCodes(params int[] statusCodes) =>
|
464 | 501 | Assign(new ReadOnlyCollection<int>(statusCodes), (a, v) => a._skipDeserializationForStatusCodes = v);
|
465 | 502 |
|
| 503 | + /// <summary> |
| 504 | + /// The user agent string to send with requests. Useful for debugging purposes to understand client and framework |
| 505 | + /// versions that initiate requests to Elasticsearch |
| 506 | + /// </summary> |
| 507 | + public T UserAgent(string userAgent) => Assign(userAgent, (a, v) => a._userAgent = v); |
| 508 | + |
466 | 509 | protected virtual void DisposeManagedResources()
|
467 | 510 | {
|
468 | 511 | _connectionPool?.Dispose();
|
|
0 commit comments