Skip to content
Open
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
7 changes: 5 additions & 2 deletions Src/Recombee.ApiClient/RecombeeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public partial class RecombeeClient
readonly byte[] secretTokenBytes;

readonly bool useHttpsAsDefault;
private readonly HttpMessageHandler handler;

readonly string hostUri = "rapi.recombee.com";

Expand All @@ -31,11 +32,13 @@ public partial class RecombeeClient
/// <param name="databaseId">ID of the database.</param>
/// <param name="secretToken">Corresponding secret token.</param>
/// <param name="useHttpsAsDefault">If true, all requests are sent using HTTPS</param>
public RecombeeClient(string databaseId, string secretToken, bool useHttpsAsDefault = true)
/// <param name="handler">Optional message handler for the http client</param>
public RecombeeClient(string databaseId, string secretToken, bool useHttpsAsDefault = true, HttpMessageHandler handler = null)
{
this.databaseId = databaseId;
this.secretTokenBytes = Encoding.ASCII.GetBytes(secretToken);
this.useHttpsAsDefault = useHttpsAsDefault;
this.handler = handler;
this.httpClient = createHttpClient();

var envHostUri = Environment.GetEnvironmentVariable("RAPI_URI");
Expand All @@ -45,7 +48,7 @@ public RecombeeClient(string databaseId, string secretToken, bool useHttpsAsDefa

private HttpClient createHttpClient()
{
var httpClient = new HttpClient();
var httpClient = handler == null ? new HttpClient() : new HttpClient(handler);
httpClient.DefaultRequestHeaders.Add("User-Agent", "recombee-.net-api-client/2.4.1");
return httpClient;
}
Expand Down