@@ -47,8 +47,10 @@ public class SocketLabsClient : ISocketLabsClient , IDisposable
4747 /// </summary>
4848 /// <param name="serverId">Your SocketLabs ServerId number.</param>
4949 /// <param name="apiKey">Your SocketLabs Injection API key.</param>
50- public SocketLabsClient ( int serverId , string apiKey ) : this ( serverId , apiKey , null )
50+ public SocketLabsClient ( int serverId , string apiKey )
5151 {
52+ _serverId = serverId ;
53+ _apiKey = apiKey ;
5254 _httpClient = BuildHttpClient ( null ) ;
5355 }
5456
@@ -65,13 +67,33 @@ public SocketLabsClient(int serverId, string apiKey, IWebProxy optionalProxy)
6567 _httpClient = BuildHttpClient ( optionalProxy ) ;
6668 }
6769
70+ /// <summary>
71+ /// Creates a new instance of the <c>SocketLabsClient</c> with a provided HttpClient.
72+ /// </summary>
73+ /// <param name="serverId">Your SocketLabs ServerId number.</param>
74+ /// <param name="apiKey">Your SocketLabs Injection API key.</param>
75+ /// <param name="httpClient">The HttpClient instance you would like to use.</param>
76+ public SocketLabsClient ( int serverId , string apiKey , HttpClient httpClient )
77+ {
78+ _serverId = serverId ;
79+ _apiKey = apiKey ;
80+
81+ _httpClient = httpClient ?? throw new ArgumentNullException ( nameof ( httpClient ) ) ;
82+ ConfigureHttpClient ( httpClient ) ;
83+ }
84+
6885 private HttpClient BuildHttpClient ( IWebProxy optionalProxy )
6986 {
7087 var httpClient = optionalProxy != null ? new HttpClient ( new HttpClientHandler ( ) { UseProxy = true , Proxy = optionalProxy } ) : new HttpClient ( ) ;
71- httpClient . DefaultRequestHeaders . UserAgent . ParseAdd ( UserAgent ) ;
88+ ConfigureHttpClient ( httpClient ) ;
7289 return httpClient ;
7390 }
7491
92+ private void ConfigureHttpClient ( HttpClient httpClient )
93+ {
94+ httpClient . DefaultRequestHeaders . UserAgent . ParseAdd ( UserAgent ) ;
95+ }
96+
7597 /// <summary>
7698 /// Quickly and easily send a basic message without the need to build up a message object
7799 /// or instantiate a SocketLabsClient.
0 commit comments