Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
version: '{build}'
skip_tags: true
image: Visual Studio 2017
configuration: Release
install:
image: Visual Studio 2019
build_script:
- ps: ./Build.ps1
test: off
Expand Down
21 changes: 18 additions & 3 deletions src/Seq.Api/Client/SeqApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Net;
using System.Net.Http;
Expand Down Expand Up @@ -56,7 +57,20 @@ public class SeqApiClient : IDisposable
/// <param name="serverUrl">The base URL of the Seq server.</param>
/// <param name="apiKey">An API key to use when making requests to the server, if required.</param>
/// <param name="useDefaultCredentials">Whether default credentials will be sent with HTTP requests; the default is <c>true</c>.</param>
public SeqApiClient(string serverUrl, string apiKey = null, bool useDefaultCredentials = true)
[Obsolete("Prefer `SeqApiClient(serverUrl, apiKey, handler => handler.UseDefaultCredentials = true)` instead."), EditorBrowsable(EditorBrowsableState.Never)]
public SeqApiClient(string serverUrl, string apiKey, bool useDefaultCredentials)
: this(serverUrl, apiKey, handler => handler.UseDefaultCredentials = useDefaultCredentials)
{
}

/// <summary>
/// Construct a <see cref="SeqApiClient"/>.
/// </summary>
/// <param name="serverUrl">The base URL of the Seq server.</param>
/// <param name="apiKey">An API key to use when making requests to the server, if required.</param>
/// <param name="configureHttpClientHandler">An optional callback to configure the <see cref="HttpClientHandler"/> used when making HTTP requests
/// to the Seq API.</param>
public SeqApiClient(string serverUrl, string apiKey = null, Action<HttpClientHandler> configureHttpClientHandler = null)
{
ServerUrl = serverUrl ?? throw new ArgumentNullException(nameof(serverUrl));

Expand All @@ -65,10 +79,11 @@ public SeqApiClient(string serverUrl, string apiKey = null, bool useDefaultCrede

var handler = new HttpClientHandler
{
CookieContainer = _cookies,
UseDefaultCredentials = useDefaultCredentials
CookieContainer = _cookies
};

configureHttpClientHandler?.Invoke(handler);

var baseAddress = serverUrl;
if (!baseAddress.EndsWith("/"))
baseAddress += "/";
Expand Down
28 changes: 26 additions & 2 deletions src/Seq.Api/SeqConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Seq.Api.Client;
Expand All @@ -27,7 +29,7 @@ namespace Seq.Api
/// <summary>
/// Exposes high-level (typed) interactions with the Seq API through various resource groups.
/// </summary>
public class SeqConnection : ISeqConnection
public class SeqConnection : ISeqConnection, IDisposable
{
readonly object _sync = new object();
readonly Dictionary<string, Task<ResourceGroup>> _resourceGroups = new Dictionary<string, Task<ResourceGroup>>();
Expand All @@ -39,12 +41,34 @@ public class SeqConnection : ISeqConnection
/// <param name="serverUrl">The base URL of the Seq server.</param>
/// <param name="apiKey">An API key to use when making requests to the server, if required.</param>
/// <param name="useDefaultCredentials">Whether default credentials will be sent with HTTP requests; the default is <c>true</c>.</param>
public SeqConnection(string serverUrl, string apiKey = null, bool useDefaultCredentials = true)
[Obsolete("Prefer `SeqConnection(serverUrl, apiKey, handler => handler.UseDefaultCredentials = true)` instead."), EditorBrowsable(EditorBrowsableState.Never)]
public SeqConnection(string serverUrl, string apiKey, bool useDefaultCredentials)
{
if (serverUrl == null) throw new ArgumentNullException(nameof(serverUrl));
Client = new SeqApiClient(serverUrl, apiKey, useDefaultCredentials);
}

/// <summary>
/// Construct a <see cref="SeqConnection"/>.
/// </summary>
/// <param name="serverUrl">The base URL of the Seq server.</param>
/// <param name="apiKey">An API key to use when making requests to the server, if required.</param>
/// <param name="configureHttpClientHandler">An optional callback to configure the <see cref="HttpClientHandler"/> used when making HTTP requests
/// to the Seq API.</param>
public SeqConnection(string serverUrl, string apiKey = null, Action<HttpClientHandler> configureHttpClientHandler = null)
{
if (serverUrl == null) throw new ArgumentNullException(nameof(serverUrl));
Client = new SeqApiClient(serverUrl, apiKey, configureHttpClientHandler);
}

/// <summary>
/// <inheritdoc/>
/// </summary>
public void Dispose()
{
Client.Dispose();
}

/// <summary>
/// Access the lower-level <see cref="SeqApiClient"/> that can be used for resource-oriented navigation through
/// the HTTP API.
Expand Down
20 changes: 20 additions & 0 deletions test/Seq.Api.Tests/SeqConnectionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Xunit;

namespace Seq.Api.Tests
{
public class SeqConnectionTests
{
[Fact]
public void WhenConstructedTheHandlerConfigurationCallbackIsCalled()
{
var callCount = 0;

using var _ = new SeqConnection("https://test.example.com", null, handler => {
Assert.NotNull(handler);
++callCount;
});

Assert.Equal(1, callCount);
}
}
}