diff --git a/Emby.Common.Implementations/HttpClientManager/HttpClientManager.cs b/Emby.Common.Implementations/HttpClientManager/HttpClientManager.cs index 06af5af536..0abcaadb1f 100644 --- a/Emby.Common.Implementations/HttpClientManager/HttpClientManager.cs +++ b/Emby.Common.Implementations/HttpClientManager/HttpClientManager.cs @@ -18,6 +18,7 @@ using System.Threading; using System.Threading.Tasks; using Emby.Common.Implementations.HttpClientManager; using MediaBrowser.Model.IO; +using MediaBrowser.Common; namespace Emby.Common.Implementations.HttpClientManager { @@ -43,6 +44,7 @@ namespace Emby.Common.Implementations.HttpClientManager private readonly IFileSystem _fileSystem; private readonly IMemoryStreamFactory _memoryStreamProvider; + private readonly IApplicationHost _appHost; /// /// Initializes a new instance of the class. @@ -257,6 +259,8 @@ namespace Emby.Common.Implementations.HttpClientManager private void AddRequestHeaders(HttpWebRequest request, HttpRequestOptions options) { + var hasUserAgent = false; + foreach (var header in options.RequestHeaders.ToList()) { if (string.Equals(header.Key, "Accept", StringComparison.OrdinalIgnoreCase)) @@ -265,11 +269,8 @@ namespace Emby.Common.Implementations.HttpClientManager } else if (string.Equals(header.Key, "User-Agent", StringComparison.OrdinalIgnoreCase)) { -#if NET46 - request.UserAgent = header.Value; -#elif NETSTANDARD1_6 - request.Headers["User-Agent"] = header.Value; -#endif + SetUserAgent(request, header.Value); + hasUserAgent = true; } else { @@ -280,6 +281,20 @@ namespace Emby.Common.Implementations.HttpClientManager #endif } } + + if (!hasUserAgent && options.EnableDefaultUserAgent) + { + SetUserAgent(request, _appHost.Name + "/" + _appHost.ApplicationVersion.ToString()); + } + } + + private void SetUserAgent(HttpWebRequest request, string userAgent) + { +#if NET46 + request.UserAgent = userAgent; +#elif NETSTANDARD1_6 + request.Headers["User-Agent"] = userAgent; +#endif } /// diff --git a/MediaBrowser.Providers/Omdb/OmdbProvider.cs b/MediaBrowser.Providers/Omdb/OmdbProvider.cs index 07b35c45ae..b42dd34b21 100644 --- a/MediaBrowser.Providers/Omdb/OmdbProvider.cs +++ b/MediaBrowser.Providers/Omdb/OmdbProvider.cs @@ -347,7 +347,8 @@ namespace MediaBrowser.Providers.Omdb Url = url, ResourcePool = ResourcePool, CancellationToken = cancellationToken, - BufferContent = true + BufferContent = true, + EnableDefaultUserAgent = true }); }