From 076e17f35556c6d1257856896619e30eb494b2bb Mon Sep 17 00:00:00 2001 From: crobibero Date: Wed, 19 Aug 2020 06:31:45 -0600 Subject: [PATCH 1/9] Add default http client --- Jellyfin.Server/Startup.cs | 15 ++- MediaBrowser.Common/Net/DefaultHttpClient.cs | 108 ++++++++++++++++++ .../Net/DefaultHttpClientHandler.cs | 18 +++ .../Net/UserAgentDelegatingHandler.cs | 52 +++++++++ 4 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 MediaBrowser.Common/Net/DefaultHttpClient.cs create mode 100644 MediaBrowser.Common/Net/DefaultHttpClientHandler.cs create mode 100644 MediaBrowser.Common/Net/UserAgentDelegatingHandler.cs diff --git a/Jellyfin.Server/Startup.cs b/Jellyfin.Server/Startup.cs index 108d8f881..05deaa2e0 100644 --- a/Jellyfin.Server/Startup.cs +++ b/Jellyfin.Server/Startup.cs @@ -1,13 +1,20 @@ +using System.Diagnostics; +using System.Net; using System.Net.Http; +using System.Reflection; +using Emby.Server.Implementations; using Jellyfin.Server.Extensions; +using Jellyfin.Server.Implementations; using Jellyfin.Server.Middleware; using Jellyfin.Server.Models; +using MediaBrowser.Common.Net; using MediaBrowser.Controller; using MediaBrowser.Controller.Configuration; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Http.Logging; using Prometheus; namespace Jellyfin.Server @@ -44,7 +51,13 @@ namespace Jellyfin.Server services.AddCustomAuthentication(); services.AddJellyfinApiAuthorization(); - services.AddHttpClient(); + + services + .AddTransient() + .AddHttpClient() + .ConfigureHttpClient((sp, options) => {}) + .ConfigurePrimaryHttpMessageHandler(x => new DefaultHttpClientHandler()) + .AddHttpMessageHandler(); } /// diff --git a/MediaBrowser.Common/Net/DefaultHttpClient.cs b/MediaBrowser.Common/Net/DefaultHttpClient.cs new file mode 100644 index 000000000..cbc06eec0 --- /dev/null +++ b/MediaBrowser.Common/Net/DefaultHttpClient.cs @@ -0,0 +1,108 @@ +using System; +using System.IO; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +namespace MediaBrowser.Common.Net +{ + /// + /// Default http client. + /// + public class DefaultHttpClient + { + private readonly HttpClient _httpClient; + + /// + /// Initializes a new instance of the class. + /// + /// Instance of httpclient. + public DefaultHttpClient(HttpClient httpClient) + { + _httpClient = httpClient; + } + + /// + /// Make GET request. + /// + /// Url to request. + /// A containing the . + public Task GetAsync(string url) + { + return _httpClient.GetAsync(url); + } + + /// + /// Make GET request. + /// + /// Url to request. + /// A containing the . + public Task GetAsync(Uri url) + { + return _httpClient.GetAsync(url); + } + + /// + /// Make GET request. + /// + /// Url to request. + /// The cancellation token. + /// A containing the . + public Task GetAsync(string url, CancellationToken cancellationToken) + { + return _httpClient.GetAsync(url, cancellationToken); + } + + /// + /// Make GET request. + /// + /// Url to request. + /// The cancellation token. + /// A containing the . + public Task GetAsync(Uri url, CancellationToken cancellationToken) + { + return _httpClient.GetAsync(url, cancellationToken); + } + + /// + /// Get stream. + /// + /// Url to get stream from. + /// A containing the . + public Task GetStreamAsync(string url) + { + return _httpClient.GetStreamAsync(url); + } + + /// + /// Get stream. + /// + /// Url to get stream from. + /// A containing the . + public Task GetStreamAsync(Uri url) + { + return _httpClient.GetStreamAsync(url); + } + + /// + /// Send request. + /// + /// The . + /// A containing the . + public Task SendAsync(HttpRequestMessage requestMessage) + { + return _httpClient.SendAsync(requestMessage); + } + + /// + /// Send request. + /// + /// The . + /// The cancellation token. + /// A containing the . + public Task SendAsync(HttpRequestMessage requestMessage, CancellationToken cancellationToken) + { + return _httpClient.SendAsync(requestMessage, cancellationToken); + } + } +} diff --git a/MediaBrowser.Common/Net/DefaultHttpClientHandler.cs b/MediaBrowser.Common/Net/DefaultHttpClientHandler.cs new file mode 100644 index 000000000..6608fad34 --- /dev/null +++ b/MediaBrowser.Common/Net/DefaultHttpClientHandler.cs @@ -0,0 +1,18 @@ +using System.Net; +using System.Net.Http; + +namespace MediaBrowser.Common.Net +{ + /// + /// Default http client handler. + /// + public class DefaultHttpClientHandler : HttpClientHandler + { + /// + public DefaultHttpClientHandler() + { + // TODO change to DecompressionMethods.All with .NET5 + AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; + } + } +} diff --git a/MediaBrowser.Common/Net/UserAgentDelegatingHandler.cs b/MediaBrowser.Common/Net/UserAgentDelegatingHandler.cs new file mode 100644 index 000000000..f527c766f --- /dev/null +++ b/MediaBrowser.Common/Net/UserAgentDelegatingHandler.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Threading; +using System.Threading.Tasks; + +namespace MediaBrowser.Common.Net +{ + /// + /// User agent delegating handler. + /// Adds User-Agent header to all requests. + /// + public class UserAgentDelegatingHandler : DelegatingHandler + { + /// + public UserAgentDelegatingHandler(IApplicationHost applicationHost) + { + UserAgentValues = new List + { + new ProductInfoHeaderValue(applicationHost.Name.Replace(' ', '-'), applicationHost.ApplicationVersionString), + new ProductInfoHeaderValue($"({Environment.OSVersion}; {applicationHost.ApplicationUserAgentAddress})") + }; + } + + /// + /// Gets or sets the user agent values. + /// + public List UserAgentValues { get; set; } + + /// + /// Send request message. + /// + /// The request message. + /// The cancellation token. + /// A containing the . + protected override Task SendAsync( + HttpRequestMessage request, + CancellationToken cancellationToken) + { + if (request.Headers.UserAgent.Count == 0) + { + foreach (var userAgentValue in UserAgentValues) + { + request.Headers.UserAgent.Add(userAgentValue); + } + } + + return base.SendAsync(request, cancellationToken); + } + } +} From 7578dfac25316946d7a65123573d404d8965937d Mon Sep 17 00:00:00 2001 From: crobibero Date: Wed, 19 Aug 2020 06:36:10 -0600 Subject: [PATCH 2/9] Remove unused directives --- Jellyfin.Server/Startup.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Jellyfin.Server/Startup.cs b/Jellyfin.Server/Startup.cs index 05deaa2e0..ea80d97b9 100644 --- a/Jellyfin.Server/Startup.cs +++ b/Jellyfin.Server/Startup.cs @@ -1,10 +1,4 @@ -using System.Diagnostics; -using System.Net; -using System.Net.Http; -using System.Reflection; -using Emby.Server.Implementations; using Jellyfin.Server.Extensions; -using Jellyfin.Server.Implementations; using Jellyfin.Server.Middleware; using Jellyfin.Server.Models; using MediaBrowser.Common.Net; @@ -14,7 +8,6 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Http.Logging; using Prometheus; namespace Jellyfin.Server From 0db0e8b944cbe83b0a81f64f6b40c651d88d1335 Mon Sep 17 00:00:00 2001 From: crobibero Date: Wed, 19 Aug 2020 06:39:29 -0600 Subject: [PATCH 3/9] Remove unused configure --- Jellyfin.Server/Startup.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Jellyfin.Server/Startup.cs b/Jellyfin.Server/Startup.cs index bb685001f..a2db7b5c1 100644 --- a/Jellyfin.Server/Startup.cs +++ b/Jellyfin.Server/Startup.cs @@ -51,7 +51,6 @@ namespace Jellyfin.Server services .AddTransient() .AddHttpClient() - .ConfigureHttpClient((sp, options) => {}) .ConfigurePrimaryHttpMessageHandler(x => new DefaultHttpClientHandler()) .AddHttpMessageHandler(); } From ac5c0866f3745784c78e376c2eefb111b929d8e5 Mon Sep 17 00:00:00 2001 From: crobibero Date: Wed, 19 Aug 2020 06:52:18 -0600 Subject: [PATCH 4/9] P E R F O R M A N C E --- .../Net/UserAgentDelegatingHandler.cs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/MediaBrowser.Common/Net/UserAgentDelegatingHandler.cs b/MediaBrowser.Common/Net/UserAgentDelegatingHandler.cs index f527c766f..c016af87c 100644 --- a/MediaBrowser.Common/Net/UserAgentDelegatingHandler.cs +++ b/MediaBrowser.Common/Net/UserAgentDelegatingHandler.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Net.Http; using System.Net.Http.Headers; using System.Threading; @@ -13,21 +12,18 @@ namespace MediaBrowser.Common.Net /// public class UserAgentDelegatingHandler : DelegatingHandler { + private readonly ProductInfoHeaderValue[] _userAgentValues; + /// public UserAgentDelegatingHandler(IApplicationHost applicationHost) { - UserAgentValues = new List + _userAgentValues = new [] { new ProductInfoHeaderValue(applicationHost.Name.Replace(' ', '-'), applicationHost.ApplicationVersionString), new ProductInfoHeaderValue($"({Environment.OSVersion}; {applicationHost.ApplicationUserAgentAddress})") }; } - /// - /// Gets or sets the user agent values. - /// - public List UserAgentValues { get; set; } - /// /// Send request message. /// @@ -40,9 +36,9 @@ namespace MediaBrowser.Common.Net { if (request.Headers.UserAgent.Count == 0) { - foreach (var userAgentValue in UserAgentValues) + for (var i = 0; i < _userAgentValues.Length; i++) { - request.Headers.UserAgent.Add(userAgentValue); + request.Headers.UserAgent.Add(_userAgentValues[i]); } } From f6b8cd4b46d03a1baa86d4ee31d1a66e2ad05097 Mon Sep 17 00:00:00 2001 From: crobibero Date: Wed, 19 Aug 2020 07:09:07 -0600 Subject: [PATCH 5/9] Fix build --- MediaBrowser.Common/Net/DefaultHttpClient.cs | 31 ------------------- .../Net/DefaultHttpClientHandler.cs | 4 ++- .../Net/UserAgentDelegatingHandler.cs | 7 +++-- 3 files changed, 8 insertions(+), 34 deletions(-) diff --git a/MediaBrowser.Common/Net/DefaultHttpClient.cs b/MediaBrowser.Common/Net/DefaultHttpClient.cs index cbc06eec0..be18e82db 100644 --- a/MediaBrowser.Common/Net/DefaultHttpClient.cs +++ b/MediaBrowser.Common/Net/DefaultHttpClient.cs @@ -22,16 +22,6 @@ namespace MediaBrowser.Common.Net _httpClient = httpClient; } - /// - /// Make GET request. - /// - /// Url to request. - /// A containing the . - public Task GetAsync(string url) - { - return _httpClient.GetAsync(url); - } - /// /// Make GET request. /// @@ -42,17 +32,6 @@ namespace MediaBrowser.Common.Net return _httpClient.GetAsync(url); } - /// - /// Make GET request. - /// - /// Url to request. - /// The cancellation token. - /// A containing the . - public Task GetAsync(string url, CancellationToken cancellationToken) - { - return _httpClient.GetAsync(url, cancellationToken); - } - /// /// Make GET request. /// @@ -64,16 +43,6 @@ namespace MediaBrowser.Common.Net return _httpClient.GetAsync(url, cancellationToken); } - /// - /// Get stream. - /// - /// Url to get stream from. - /// A containing the . - public Task GetStreamAsync(string url) - { - return _httpClient.GetStreamAsync(url); - } - /// /// Get stream. /// diff --git a/MediaBrowser.Common/Net/DefaultHttpClientHandler.cs b/MediaBrowser.Common/Net/DefaultHttpClientHandler.cs index 6608fad34..e189d6e70 100644 --- a/MediaBrowser.Common/Net/DefaultHttpClientHandler.cs +++ b/MediaBrowser.Common/Net/DefaultHttpClientHandler.cs @@ -8,7 +8,9 @@ namespace MediaBrowser.Common.Net /// public class DefaultHttpClientHandler : HttpClientHandler { - /// + /// + /// Initializes a new instance of the class. + /// public DefaultHttpClientHandler() { // TODO change to DecompressionMethods.All with .NET5 diff --git a/MediaBrowser.Common/Net/UserAgentDelegatingHandler.cs b/MediaBrowser.Common/Net/UserAgentDelegatingHandler.cs index c016af87c..31af85f7d 100644 --- a/MediaBrowser.Common/Net/UserAgentDelegatingHandler.cs +++ b/MediaBrowser.Common/Net/UserAgentDelegatingHandler.cs @@ -14,10 +14,13 @@ namespace MediaBrowser.Common.Net { private readonly ProductInfoHeaderValue[] _userAgentValues; - /// + /// + /// Initializes a new instance of the class. + /// + /// Instance of the interface. public UserAgentDelegatingHandler(IApplicationHost applicationHost) { - _userAgentValues = new [] + _userAgentValues = new[] { new ProductInfoHeaderValue(applicationHost.Name.Replace(' ', '-'), applicationHost.ApplicationVersionString), new ProductInfoHeaderValue($"({Environment.OSVersion}; {applicationHost.ApplicationUserAgentAddress})") From abb79bf810a25331a9c84958690e7af7717499e6 Mon Sep 17 00:00:00 2001 From: crobibero Date: Wed, 19 Aug 2020 13:41:00 -0600 Subject: [PATCH 6/9] remove OS and email from default UserAgent --- MediaBrowser.Common/Net/UserAgentDelegatingHandler.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/MediaBrowser.Common/Net/UserAgentDelegatingHandler.cs b/MediaBrowser.Common/Net/UserAgentDelegatingHandler.cs index 31af85f7d..74dc22b7a 100644 --- a/MediaBrowser.Common/Net/UserAgentDelegatingHandler.cs +++ b/MediaBrowser.Common/Net/UserAgentDelegatingHandler.cs @@ -1,5 +1,4 @@ -using System; -using System.Net.Http; +using System.Net.Http; using System.Net.Http.Headers; using System.Threading; using System.Threading.Tasks; @@ -22,8 +21,7 @@ namespace MediaBrowser.Common.Net { _userAgentValues = new[] { - new ProductInfoHeaderValue(applicationHost.Name.Replace(' ', '-'), applicationHost.ApplicationVersionString), - new ProductInfoHeaderValue($"({Environment.OSVersion}; {applicationHost.ApplicationUserAgentAddress})") + new ProductInfoHeaderValue(applicationHost.Name.Replace(' ', '-'), applicationHost.ApplicationVersionString) }; } From 64a811d78333287647abf2c5193d005b5758eec3 Mon Sep 17 00:00:00 2001 From: crobibero Date: Mon, 31 Aug 2020 08:47:38 -0600 Subject: [PATCH 7/9] use named http clients --- Jellyfin.Server/Startup.cs | 23 ++++-- MediaBrowser.Common/Net/DefaultHttpClient.cs | 77 ------------------- MediaBrowser.Common/Net/NamedClient.cs | 18 +++++ .../Net/UserAgentDelegatingHandler.cs | 49 ------------ 4 files changed, 36 insertions(+), 131 deletions(-) delete mode 100644 MediaBrowser.Common/Net/DefaultHttpClient.cs create mode 100644 MediaBrowser.Common/Net/NamedClient.cs delete mode 100644 MediaBrowser.Common/Net/UserAgentDelegatingHandler.cs diff --git a/Jellyfin.Server/Startup.cs b/Jellyfin.Server/Startup.cs index a2db7b5c1..eb74d906f 100644 --- a/Jellyfin.Server/Startup.cs +++ b/Jellyfin.Server/Startup.cs @@ -1,9 +1,11 @@ using System; using System.ComponentModel; +using System.Net.Http.Headers; using Jellyfin.Api.TypeConverters; using Jellyfin.Server.Extensions; using Jellyfin.Server.Middleware; using Jellyfin.Server.Models; +using MediaBrowser.Common; using MediaBrowser.Common.Net; using MediaBrowser.Controller; using MediaBrowser.Controller.Configuration; @@ -21,14 +23,17 @@ namespace Jellyfin.Server public class Startup { private readonly IServerConfigurationManager _serverConfigurationManager; + private readonly IApplicationHost _applicationHost; /// /// Initializes a new instance of the class. /// /// The server configuration manager. - public Startup(IServerConfigurationManager serverConfigurationManager) + /// The application host. + public Startup(IServerConfigurationManager serverConfigurationManager, IApplicationHost applicationHost) { _serverConfigurationManager = serverConfigurationManager; + _applicationHost = applicationHost; } /// @@ -49,10 +54,18 @@ namespace Jellyfin.Server services.AddJellyfinApiAuthorization(); services - .AddTransient() - .AddHttpClient() - .ConfigurePrimaryHttpMessageHandler(x => new DefaultHttpClientHandler()) - .AddHttpMessageHandler(); + .AddHttpClient(NamedClient.Default, c => + { + c.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(_applicationHost.Name.Replace(' ', '-'), _applicationHost.ApplicationVersionString)); + }) + .ConfigurePrimaryHttpMessageHandler(x => new DefaultHttpClientHandler()); + + services.AddHttpClient(NamedClient.MusicBrainz, c => + { + c.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(_applicationHost.Name.Replace(' ', '-'), _applicationHost.ApplicationVersionString)); + c.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(_applicationHost.ApplicationUserAgentAddress)); + }) + .ConfigurePrimaryHttpMessageHandler(x => new DefaultHttpClientHandler()); } /// diff --git a/MediaBrowser.Common/Net/DefaultHttpClient.cs b/MediaBrowser.Common/Net/DefaultHttpClient.cs deleted file mode 100644 index be18e82db..000000000 --- a/MediaBrowser.Common/Net/DefaultHttpClient.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System; -using System.IO; -using System.Net.Http; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.Common.Net -{ - /// - /// Default http client. - /// - public class DefaultHttpClient - { - private readonly HttpClient _httpClient; - - /// - /// Initializes a new instance of the class. - /// - /// Instance of httpclient. - public DefaultHttpClient(HttpClient httpClient) - { - _httpClient = httpClient; - } - - /// - /// Make GET request. - /// - /// Url to request. - /// A containing the . - public Task GetAsync(Uri url) - { - return _httpClient.GetAsync(url); - } - - /// - /// Make GET request. - /// - /// Url to request. - /// The cancellation token. - /// A containing the . - public Task GetAsync(Uri url, CancellationToken cancellationToken) - { - return _httpClient.GetAsync(url, cancellationToken); - } - - /// - /// Get stream. - /// - /// Url to get stream from. - /// A containing the . - public Task GetStreamAsync(Uri url) - { - return _httpClient.GetStreamAsync(url); - } - - /// - /// Send request. - /// - /// The . - /// A containing the . - public Task SendAsync(HttpRequestMessage requestMessage) - { - return _httpClient.SendAsync(requestMessage); - } - - /// - /// Send request. - /// - /// The . - /// The cancellation token. - /// A containing the . - public Task SendAsync(HttpRequestMessage requestMessage, CancellationToken cancellationToken) - { - return _httpClient.SendAsync(requestMessage, cancellationToken); - } - } -} diff --git a/MediaBrowser.Common/Net/NamedClient.cs b/MediaBrowser.Common/Net/NamedClient.cs new file mode 100644 index 000000000..0f6161c32 --- /dev/null +++ b/MediaBrowser.Common/Net/NamedClient.cs @@ -0,0 +1,18 @@ +namespace MediaBrowser.Common.Net +{ + /// + /// Registered http client names. + /// + public static class NamedClient + { + /// + /// Gets the value for the default named http client. + /// + public const string Default = nameof(Default); + + /// + /// Gets the value for the MusicBrainz named http client. + /// + public const string MusicBrainz = nameof(MusicBrainz); + } +} diff --git a/MediaBrowser.Common/Net/UserAgentDelegatingHandler.cs b/MediaBrowser.Common/Net/UserAgentDelegatingHandler.cs deleted file mode 100644 index 74dc22b7a..000000000 --- a/MediaBrowser.Common/Net/UserAgentDelegatingHandler.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Net.Http; -using System.Net.Http.Headers; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.Common.Net -{ - /// - /// User agent delegating handler. - /// Adds User-Agent header to all requests. - /// - public class UserAgentDelegatingHandler : DelegatingHandler - { - private readonly ProductInfoHeaderValue[] _userAgentValues; - - /// - /// Initializes a new instance of the class. - /// - /// Instance of the interface. - public UserAgentDelegatingHandler(IApplicationHost applicationHost) - { - _userAgentValues = new[] - { - new ProductInfoHeaderValue(applicationHost.Name.Replace(' ', '-'), applicationHost.ApplicationVersionString) - }; - } - - /// - /// Send request message. - /// - /// The request message. - /// The cancellation token. - /// A containing the . - protected override Task SendAsync( - HttpRequestMessage request, - CancellationToken cancellationToken) - { - if (request.Headers.UserAgent.Count == 0) - { - for (var i = 0; i < _userAgentValues.Length; i++) - { - request.Headers.UserAgent.Add(_userAgentValues[i]); - } - } - - return base.SendAsync(request, cancellationToken); - } - } -} From 808d180be4c0317bdca4862ebd3068029d13c95e Mon Sep 17 00:00:00 2001 From: crobibero Date: Mon, 31 Aug 2020 08:52:21 -0600 Subject: [PATCH 8/9] Fix user agent comment --- Jellyfin.Server/Startup.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jellyfin.Server/Startup.cs b/Jellyfin.Server/Startup.cs index eb74d906f..a468f4dff 100644 --- a/Jellyfin.Server/Startup.cs +++ b/Jellyfin.Server/Startup.cs @@ -63,7 +63,7 @@ namespace Jellyfin.Server services.AddHttpClient(NamedClient.MusicBrainz, c => { c.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(_applicationHost.Name.Replace(' ', '-'), _applicationHost.ApplicationVersionString)); - c.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(_applicationHost.ApplicationUserAgentAddress)); + c.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue($"({_applicationHost.ApplicationUserAgentAddress})")); }) .ConfigurePrimaryHttpMessageHandler(x => new DefaultHttpClientHandler()); } From e48df7da5e3d3eb81f68e71c0fe27a64063f00ac Mon Sep 17 00:00:00 2001 From: crobibero Date: Mon, 31 Aug 2020 09:15:20 -0600 Subject: [PATCH 9/9] Only create product header once --- Jellyfin.Server/Startup.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Jellyfin.Server/Startup.cs b/Jellyfin.Server/Startup.cs index a468f4dff..f50e5716d 100644 --- a/Jellyfin.Server/Startup.cs +++ b/Jellyfin.Server/Startup.cs @@ -53,16 +53,17 @@ namespace Jellyfin.Server services.AddJellyfinApiAuthorization(); + var productHeader = new ProductInfoHeaderValue(_applicationHost.Name.Replace(' ', '-'), _applicationHost.ApplicationVersionString); services .AddHttpClient(NamedClient.Default, c => { - c.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(_applicationHost.Name.Replace(' ', '-'), _applicationHost.ApplicationVersionString)); + c.DefaultRequestHeaders.UserAgent.Add(productHeader); }) .ConfigurePrimaryHttpMessageHandler(x => new DefaultHttpClientHandler()); services.AddHttpClient(NamedClient.MusicBrainz, c => { - c.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(_applicationHost.Name.Replace(' ', '-'), _applicationHost.ApplicationVersionString)); + c.DefaultRequestHeaders.UserAgent.Add(productHeader); c.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue($"({_applicationHost.ApplicationUserAgentAddress})")); }) .ConfigurePrimaryHttpMessageHandler(x => new DefaultHttpClientHandler());