diff --git a/src/RestClient/RestClient/src/Http/CoreRestClientOptions.cs b/src/RestClient/RestClient/src/Http/CoreRestClientOptions.cs index a5e648a..e7fbbad 100644 --- a/src/RestClient/RestClient/src/Http/CoreRestClientOptions.cs +++ b/src/RestClient/RestClient/src/Http/CoreRestClientOptions.cs @@ -6,5 +6,6 @@ public class CoreRestClientOptions { public CompressionMethod CompressionMethod { get; set; } = CompressionMethod.None; public IAuthenticator? Authenticator { get; set; } = null; + public string? DefaultUserAgent { get; set; } } } diff --git a/src/RestClient/RestClient/src/RestClient.cs b/src/RestClient/RestClient/src/RestClient.cs index 0d356f7..af0514b 100644 --- a/src/RestClient/RestClient/src/RestClient.cs +++ b/src/RestClient/RestClient/src/RestClient.cs @@ -1,7 +1,8 @@ -namespace ClickView.Extensions.RestClient +namespace ClickView.Extensions.RestClient { using System; using System.Net.Http; + using System.Net.Http.Headers; using System.Threading; using System.Threading.Tasks; using Exceptions; @@ -15,6 +16,7 @@ public class RestClient private readonly Uri? _baseAddress; private readonly HttpClient _httpClient; private readonly CoreRestClientOptions _options; + private readonly ProductInfoHeaderValue? _userAgent; /// /// Initializes a new instance of the class @@ -26,8 +28,9 @@ public RestClient(Uri baseAddress, RestClientOptions? options = null) _baseAddress = baseAddress ?? throw new ArgumentNullException(nameof(baseAddress)); var o = options ?? RestClientOptions.Default; - _options = o; + _options = o; + _userAgent = GetDefaultUserAgent(_options.DefaultUserAgent); _httpClient = CreateClient(o); } @@ -40,6 +43,8 @@ public RestClient(HttpClient httpClient, CoreRestClientOptions? options = null) { _httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); _options = options ?? RestClientOptions.Default; + _userAgent = GetDefaultUserAgent(_options.DefaultUserAgent); + _baseAddress = null; } @@ -71,8 +76,6 @@ public async Task ExecuteAsync(BaseRestClientRequest ExecuteAsync(BaseRestClientRequest ExecuteAsync(BaseRestClientRequest