You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lidarr/src/NzbDrone.Common/Http/UserAgentBuilder.cs

41 lines
1.0 KiB

using NzbDrone.Common.EnvironmentInfo;
namespace NzbDrone.Common.Http
{
public interface IUserAgentBuilder
{
string GetUserAgent(bool simplified = false);
}
public class UserAgentBuilder : IUserAgentBuilder
{
private readonly string _userAgentSimplified;
private readonly string _userAgent;
public string GetUserAgent(bool simplified)
{
if (simplified)
{
return _userAgentSimplified;
}
return _userAgent;
}
public UserAgentBuilder(IOsInfo osInfo)
{
var osName = OsInfo.Os.ToString();
if (!string.IsNullOrWhiteSpace(osInfo.Name))
{
osName = osInfo.Name.ToLower();
}
var osVersion = osInfo.Version?.ToLower();
_userAgent = $"{BuildInfo.AppName}/{BuildInfo.Version} ({osName} {osVersion})";
_userAgentSimplified = $"{BuildInfo.AppName}/{BuildInfo.Version.ToString(2)}";
}
}
}