22using System . Globalization ;
33using System . Linq ;
44using System . Net ;
5+ using System . Net . Security ;
56using System . Reflection ;
67using System . Security . Authentication ;
78using System . Security . Cryptography ;
@@ -47,6 +48,7 @@ internal class DigestAuthenticatorManager
4748 /// </summary>
4849 private string ? _realm ;
4950
51+ private readonly RestClientOptions ? _handshakeClientOptions ;
5052 /// <summary>
5153 /// The opaque that is returned by the first digest request (without the data).
5254 /// </summary>
@@ -65,7 +67,7 @@ static DigestAuthenticatorManager()
6567 /// <param name="password">The password.</param>
6668 /// <param name="timeout">The timeout.</param>
6769 /// <param name="logger"></param>
68- public DigestAuthenticatorManager ( Uri host , string username , string password , TimeSpan timeout , ILogger logger )
70+ public DigestAuthenticatorManager ( Uri host , string username , string password , TimeSpan timeout , RestClientOptions ? handshakeClientOptions , ILogger logger )
6971 {
7072 if ( string . IsNullOrWhiteSpace ( username ) )
7173 {
@@ -87,6 +89,7 @@ public DigestAuthenticatorManager(Uri host, string username, string password, Ti
8789 _password = password ;
8890 _timeout = timeout ;
8991 _logger = logger ;
92+ _handshakeClientOptions = handshakeClientOptions ;
9093 }
9194
9295 /// <summary>
@@ -98,7 +101,7 @@ public DigestAuthenticatorManager(Uri host, string username, string password, Ti
98101 public async Task GetDigestAuthHeader (
99102 string path ,
100103 Method method ,
101- IWebProxy ? proxy = default )
104+ IWebProxy ? proxy = null )
102105 {
103106 _logger . LogDebug ( "Initiating GetDigestAuthHeader" ) ;
104107 var uri = new Uri ( _host , path ) ;
@@ -108,11 +111,19 @@ public async Task GetDigestAuthHeader(
108111 request . AddOrUpdateHeader ( "User-Agent" , $ "RestSharp.Authenticators.Digest/{ _assemblyVersion } ") ;
109112 request . AddOrUpdateHeader ( "Accept-Encoding" , "gzip, deflate, br" ) ;
110113 request . Timeout = _timeout ;
111- using var client = new RestClient ( new RestClientOptions ( )
114+
115+ RestClient client ;
116+ if ( _handshakeClientOptions != null )
117+ {
118+ client = new RestClient ( _handshakeClientOptions ) ;
119+ }
120+ else
112121 {
113- Proxy = proxy
114- } ) ;
122+ client = new RestClient ( new RestClientOptions ( ) { Proxy = proxy } ) ;
123+ }
124+
115125 var response = await client . ExecuteAsync ( request ) . ConfigureAwait ( false ) ;
126+ client . Dispose ( ) ;
116127 GetDigestDataFromFailResponse ( response ) ;
117128 _logger . LogDebug ( "GetDigestAuthHeader completed" ) ;
118129 }
0 commit comments