Skip to content

Commit

Permalink
Merge pull request #191 from Nexmo/bugfix/malformed_user_agents
Browse files Browse the repository at this point in the history
Fixing malformed user agents
  • Loading branch information
slorello89 authored Feb 11, 2020
2 parents dae26d6 + 597873a commit 211055b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Nexmo.Api/Request/VersionedApiRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,19 @@ internal static void SetUserAgent(ref HttpRequestMessage request, Credentials cr
{
if (string.IsNullOrEmpty(_userAgent))
{
#if NETSTANDARD1_6 || NETSTANDARD2_0
#if NETSTANDARD1_6 || NETSTANDARD2_0 || NETSTANDARD2_1
// TODO: watch the next core release; may have functionality to make this cleaner
var runtimeVersion = (System.Runtime.InteropServices.RuntimeInformation.OSDescription + System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription)
var languageVersion = (System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription)
.Replace(" ", "")
.Replace("/", "")
.Replace(":", "")
.Replace(";", "")
.Replace("_", "")
.Replace("(", "")
.Replace(")", "")
;
#else
var runtimeVersion = System.Diagnostics.FileVersionInfo
var languageVersion = System.Diagnostics.FileVersionInfo
.GetVersionInfo(typeof(int).Assembly.Location)
.ProductVersion;
#endif
Expand All @@ -116,7 +118,7 @@ internal static void SetUserAgent(ref HttpRequestMessage request, Credentials cr
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
.InformationalVersion;

_userAgent = $"nexmo-dotnet/{libraryVersion} dotnet/{runtimeVersion}";
_userAgent = $"nexmo-dotnet/{libraryVersion} dotnet/{languageVersion}";

var appVersion = creds?.AppUserAgent ?? Configuration.Instance.Settings["appSettings:Nexmo.UserAgent"];
if (!string.IsNullOrWhiteSpace(appVersion))
Expand Down

0 comments on commit 211055b

Please # to comment.