In some environement, specific control to the proxy configuration and SSL certificate verification is required. This patch allow the user of the library to use custom HTTP client configuration.
For example, this code allow the user to disable SSL certificate verification for dev. environement, where self-signed certificates are commonly used:
var handler = new HttpClientHandler()
{
AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate),
ClientCertificateOptions = ClientCertificateOption.Manual,
ServerCertificateCustomValidationCallback = (_, _, _, _) => true,
};
var client = new HttpClient(handler);
serviceCollection.AddSolrNet($"https://myinstance.local/solr",
null,
(url) => new AutoSolrConnection(url, client, new InsecureHttpWebRequestFactory()));
with the following WebRequestFactory
public class InsecureHttpWebRequestFactory : IHttpWebRequestFactory
{
public IHttpWebRequest Create(Uri url)
{
var req = (HttpWebRequest)WebRequest.Create(url);
req.ServerCertificateValidationCallback += (_, _, _, _) => true;
return new HttpWebRequestAdapter(req);
}
}
or to enable specific proxy to be specified with
var handler = new HttpClientHandler()
{
AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate),
Proxy = new WebProxy()
{
Address = new Uri("http://myproxy.local:3128/"),
BypassList = new[] { "localhost, 127.0.0.1, .local" }
}
};
The code has been fully tested in a larger scale application.
⚠️ Why SolRNet requires both an HttpClient and a WebRequestFactory should probably be checked. In addition, WebRequest are obsolete and should be replaced by HttpClient. I did not want to mix these two changes, the latter having much more impact.
In some environement, specific control to the proxy configuration and SSL certificate verification is required. This patch allow the user of the library to use custom HTTP client configuration.
For example, this code allow the user to disable SSL certificate verification for dev. environement, where self-signed certificates are commonly used:
with the following
WebRequestFactory
or to enable specific proxy to be specified with
The code has been fully tested in a larger scale application.
⚠️ Why SolRNet requires both an
HttpClient
and aWebRequestFactory
should probably be checked. In addition,WebRequest
are obsolete and should be replaced byHttpClient
. I did not want to mix these two changes, the latter having much more impact.