Skip to content

Commit 26abc69

Browse files
committed
Add cert callback to Http
1 parent f8154fa commit 26abc69

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

RestSharp/Http.cs

+7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#if FRAMEWORK
3232
using System.Net.Cache;
33+
using System.Net.Security;
3334
using System.Security.Cryptography.X509Certificates;
3435
using System.Text.RegularExpressions;
3536
#endif
@@ -208,6 +209,12 @@ public Encoding Encoding
208209
/// </summary>
209210
public RequestCachePolicy CachePolicy { get; set; }
210211
#endif
212+
#if NET45
213+
/// <summary>
214+
/// Callback function for handling the validation of remote certificates.
215+
/// </summary>
216+
public RemoteCertificateValidationCallback RemoteCertificateValidationCallback { get; set; }
217+
#endif
211218

212219
/// <summary>
213220
/// Default constructor

RestSharp/IHttp.cs

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#if FRAMEWORK
2626
using System.Net.Cache;
27+
using System.Net.Security;
2728
using System.Security.Cryptography.X509Certificates;
2829
#endif
2930

@@ -129,6 +130,9 @@ public interface IHttp
129130
HttpResponse AsGet(string httpMethod);
130131

131132
IWebProxy Proxy { get; set; }
133+
#endif
134+
#if NET45
135+
RemoteCertificateValidationCallback RemoteCertificateValidationCallback { get; set; }
132136
#endif
133137
}
134138
}

RestSharp/RestClient.cs

+7
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ public partial class RestClient : IRestClient
118118
public bool PreAuthenticate { get; set; }
119119

120120
#if NET45
121+
/// <summary>
122+
/// Callback function for handling the validation of remote certificates. Useful for certificate pinning and
123+
/// overriding certificate errors in the scope of a request.
124+
/// </summary>
121125
public RemoteCertificateValidationCallback RemoteCertificateValidationCallback { get; set; }
122126
#endif
123127

@@ -544,6 +548,9 @@ private void ConfigureHttp(IRestRequest request, IHttp http)
544548
}
545549
#if FRAMEWORK
546550
this.ConfigureProxy(http);
551+
#endif
552+
#if NET45
553+
http.RemoteCertificateValidationCallback = this.RemoteCertificateValidationCallback;
547554
#endif
548555
}
549556

0 commit comments

Comments
 (0)