66using System . Collections . Generic ;
77using System . Collections . Specialized ;
88using System . Security . Cryptography . X509Certificates ;
9+
910using Elastic . Transport . Extensions ;
1011
1112namespace Elastic . Transport ;
@@ -108,7 +109,6 @@ public interface IRequestConfiguration
108109 /// </summary>
109110 TimeSpan ? RequestTimeout { get ; }
110111
111-
112112 /// <summary> Specifies the headers from the response that should be parsed. </summary>
113113 HeadersList ? ResponseHeadersToParse { get ; }
114114
@@ -163,6 +163,48 @@ public record RequestConfiguration : IRequestConfiguration
163163 /// <summary> The default ping timeout when the connection is over HTTPS. Defaults to 5 seconds </summary>
164164 public static readonly TimeSpan DefaultPingTimeoutOnSsl = TimeSpan . FromSeconds ( 5 ) ;
165165
166+ /// <inheritdoc cref="IRequestConfiguration"/>
167+ public RequestConfiguration ( )
168+ {
169+ }
170+
171+ /// <inheritdoc cref="IRequestConfiguration"/>
172+ public RequestConfiguration ( IRequestConfiguration config )
173+ {
174+ #if NET8_0_OR_GREATER
175+ ArgumentNullException . ThrowIfNull ( config ) ;
176+ #else
177+ if ( config is null )
178+ throw new ArgumentNullException ( nameof ( config ) ) ;
179+ #endif
180+
181+ Accept = config . Accept ;
182+ AllowedStatusCodes = config . AllowedStatusCodes ;
183+ Authentication = config . Authentication ;
184+ ClientCertificates = ( config . ClientCertificates is null ) ? null : new X509CertificateCollection ( config . ClientCertificates ) ;
185+ ContentType = config . ContentType ;
186+ DisableDirectStreaming = config . DisableDirectStreaming ;
187+ DisableAuditTrail = config . DisableAuditTrail ;
188+ DisablePings = config . DisablePings ;
189+ DisableSniff = config . DisableSniff ;
190+ HttpPipeliningEnabled = config . HttpPipeliningEnabled ;
191+ EnableHttpCompression = config . EnableHttpCompression ;
192+ ForceNode = config . ForceNode ;
193+ MaxRetries = config . MaxRetries ;
194+ MaxRetryTimeout = config . MaxRetryTimeout ;
195+ OpaqueId = config . OpaqueId ;
196+ PingTimeout = config . PingTimeout ;
197+ RequestTimeout = config . RequestTimeout ;
198+ RunAs = config . RunAs ;
199+ ThrowExceptions = config . ThrowExceptions ;
200+ TransferEncodingChunked = config . TransferEncodingChunked ;
201+ Headers = ( config . Headers is null ) ? null : new NameValueCollection ( config . Headers ) ;
202+ EnableTcpStats = config . EnableTcpStats ;
203+ EnableThreadPoolStats = config . EnableThreadPoolStats ;
204+ ResponseHeadersToParse = ( config . ResponseHeadersToParse is null ) ? null : new HeadersList ( config . ResponseHeadersToParse ) ;
205+ ParseAllHeaders = config . ParseAllHeaders ;
206+ RequestMetaData = config . RequestMetaData ;
207+ }
166208
167209 /// <inheritdoc />
168210 public string ? Accept { get ; init ; }
@@ -188,18 +230,12 @@ public record RequestConfiguration : IRequestConfiguration
188230 /// <inheritdoc />
189231 public bool ? DisablePings { get ; init ; }
190232
191- /// <inheritdoc />
192- public bool ? DisablePing { get ; init ; }
193-
194233 /// <inheritdoc />
195234 public bool ? DisableSniff { get ; init ; }
196235
197236 /// <inheritdoc />
198237 public bool ? HttpPipeliningEnabled { get ; init ; }
199238
200- /// <inheritdoc />
201- public bool ? EnableHttpPipelining { get ; init ; } = true ;
202-
203239 /// <inheritdoc />
204240 public bool ? EnableHttpCompression { get ; init ; }
205241
@@ -247,7 +283,6 @@ public record RequestConfiguration : IRequestConfiguration
247283
248284 /// <inheritdoc />
249285 public RequestMetaData ? RequestMetaData { get ; init ; }
250-
251286}
252287
253288/// <inheritdoc cref="IRequestConfiguration"/>
@@ -256,6 +291,40 @@ public class RequestConfigurationDescriptor : IRequestConfiguration
256291 /// <inheritdoc cref="IRequestConfiguration"/>
257292 public RequestConfigurationDescriptor ( ) { }
258293
294+ /// <inheritdoc cref="IRequestConfiguration"/>
295+ public RequestConfigurationDescriptor ( IRequestConfiguration ? config )
296+ {
297+ if ( config is null )
298+ return ;
299+
300+ _accept = config . Accept ;
301+ _allowedStatusCodes = config . AllowedStatusCodes ;
302+ _authentication = config . Authentication ;
303+ _clientCertificates = ( config . ClientCertificates is null ) ? null : new X509CertificateCollection ( config . ClientCertificates ) ; ;
304+ _contentType = config . ContentType ;
305+ _disableDirectStreaming = config . DisableDirectStreaming ;
306+ _disableAuditTrail = config . DisableAuditTrail ;
307+ _disablePings = config . DisablePings ;
308+ _disableSniff = config . DisableSniff ;
309+ _httpPipeliningEnabled = config . HttpPipeliningEnabled ;
310+ _enableHttpCompression = config . EnableHttpCompression ;
311+ _forceNode = config . ForceNode ;
312+ _maxRetries = config . MaxRetries ;
313+ _maxRetryTimeout = config . MaxRetryTimeout ;
314+ _opaqueId = config . OpaqueId ;
315+ _pingTimeout = config . PingTimeout ;
316+ _requestTimeout = config . RequestTimeout ;
317+ _runAs = config . RunAs ;
318+ _throwExceptions = config . ThrowExceptions ;
319+ _transferEncodingChunked = config . TransferEncodingChunked ;
320+ _headers = ( config . Headers is null ) ? null : new NameValueCollection ( config . Headers ) ;
321+ _enableTcpStats = config . EnableTcpStats ;
322+ _enableThreadPoolStats = config . EnableThreadPoolStats ;
323+ _responseHeadersToParse = ( config . ResponseHeadersToParse is null ) ? null : new HeadersList ( config . ResponseHeadersToParse ) ;
324+ _parseAllHeaders = config . ParseAllHeaders ;
325+ _requestMetaData = config . RequestMetaData ;
326+ }
327+
259328 private string ? _accept ;
260329 private IReadOnlyCollection < int > ? _allowedStatusCodes ;
261330 private AuthorizationHeader ? _authentication ;
@@ -266,8 +335,10 @@ public RequestConfigurationDescriptor() { }
266335 private bool ? _disablePings ;
267336 private bool ? _disableSniff ;
268337 private bool ? _httpPipeliningEnabled ;
338+ private bool ? _enableHttpCompression ;
269339 private Uri ? _forceNode ;
270340 private int ? _maxRetries ;
341+ private TimeSpan ? _maxRetryTimeout ;
271342 private string ? _opaqueId ;
272343 private bool ? _parseAllHeaders ;
273344 private TimeSpan ? _pingTimeout ;
@@ -281,12 +352,6 @@ public RequestConfigurationDescriptor() { }
281352 private bool ? _enableThreadPoolStats ;
282353 private RequestMetaData ? _requestMetaData ;
283354
284- #pragma warning disable CS0649 // Field is never assigned to, and will always have its default value
285- private bool ? _enableHttpCompression ;
286- private TimeSpan ? _maxRetryTimeout ;
287- #pragma warning restore CS0649 // Field is never assigned to, and will always have its default value
288-
289-
290355 /// <inheritdoc cref="IRequestConfiguration.RunAs"/>
291356 public RequestConfigurationDescriptor RunAs ( string username )
292357 {
@@ -392,6 +457,13 @@ public RequestConfigurationDescriptor MaxRetries(int retry)
392457 return this ;
393458 }
394459
460+ /// <inheritdoc cref="IRequestConfiguration.MaxRetryTimeout"/>
461+ public RequestConfigurationDescriptor MaxRetries ( TimeSpan ? timeout )
462+ {
463+ _maxRetryTimeout = timeout ;
464+ return this ;
465+ }
466+
395467 /// <inheritdoc cref="AuthorizationHeader"/>
396468 public RequestConfigurationDescriptor Authentication ( AuthorizationHeader authentication )
397469 {
@@ -406,6 +478,13 @@ public RequestConfigurationDescriptor EnableHttpPipelining(bool enable = true)
406478 return this ;
407479 }
408480
481+ /// <inheritdoc cref="IRequestConfiguration.EnableHttpCompression"/>
482+ public RequestConfigurationDescriptor EnableHttpCompression ( bool enable = true )
483+ {
484+ _enableHttpCompression = enable ;
485+ return this ;
486+ }
487+
409488 /// <inheritdoc cref="IRequestConfiguration.ClientCertificates"/>
410489 public RequestConfigurationDescriptor ClientCertificates ( X509CertificateCollection certificates )
411490 {
0 commit comments