Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/SocketLabs/InjectionApi/SocketLabsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ public class SocketLabsClient : ISocketLabsClient , IDisposable
/// </summary>
/// <param name="serverId">Your SocketLabs ServerId number.</param>
/// <param name="apiKey">Your SocketLabs Injection API key.</param>
public SocketLabsClient(int serverId, string apiKey):this(serverId, apiKey, null)
public SocketLabsClient(int serverId, string apiKey)
{
_serverId = serverId;
_apiKey = apiKey;
_httpClient = BuildHttpClient(null);
}

Expand All @@ -65,13 +67,33 @@ public SocketLabsClient(int serverId, string apiKey, IWebProxy optionalProxy)
_httpClient = BuildHttpClient(optionalProxy);
}

/// <summary>
/// Creates a new instance of the <c>SocketLabsClient</c> with a provided HttpClient.
/// </summary>
/// <param name="serverId">Your SocketLabs ServerId number.</param>
/// <param name="apiKey">Your SocketLabs Injection API key.</param>
/// <param name="httpClient">The HttpClient instance you would like to use.</param>
public SocketLabsClient(int serverId, string apiKey, HttpClient httpClient)
{
_serverId = serverId;
_apiKey = apiKey;

_httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
ConfigureHttpClient(httpClient);
}

private HttpClient BuildHttpClient(IWebProxy optionalProxy)
{
var httpClient = optionalProxy != null ? new HttpClient(new HttpClientHandler() {UseProxy = true, Proxy = optionalProxy}) : new HttpClient();
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent);
ConfigureHttpClient(httpClient);
return httpClient;
}

private void ConfigureHttpClient(HttpClient httpClient)
{
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent);
}

/// <summary>
/// Quickly and easily send a basic message without the need to build up a message object
/// or instantiate a SocketLabsClient.
Expand Down