From a1e63286ba14101160b20fcf5f6943d6acaaab0b Mon Sep 17 00:00:00 2001 From: RTLCoil Date: Mon, 20 Sep 2021 23:13:25 +0300 Subject: [PATCH] Address review comments --- CloudinaryDotNet.Tests/Asset/UrlBuilderTest.cs | 10 +++++----- CloudinaryDotNet/ApiShared.Internal.cs | 5 +++-- CloudinaryDotNet/ApiShared.cs | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CloudinaryDotNet.Tests/Asset/UrlBuilderTest.cs b/CloudinaryDotNet.Tests/Asset/UrlBuilderTest.cs index b8c98dcc..c83e619f 100644 --- a/CloudinaryDotNet.Tests/Asset/UrlBuilderTest.cs +++ b/CloudinaryDotNet.Tests/Asset/UrlBuilderTest.cs @@ -494,7 +494,7 @@ public void TestAgentPlatformHeaders() var httpRequestMessage = CreateRequest("UserPlatform/2.3"); //Can't test the result, so we just verify the UserAgent parameter is sent to the server - StringAssert.IsMatch(@"CloudinaryDotNet\/(\d+)\.(\d+)\.(\d+) \(" + ApiShared.USER_AGENT.Replace("(", "").Replace(")", "") + @"\) UserPlatform/2\.3", + StringAssert.IsMatch(@"CloudinaryDotNet\/(\d+)\.(\d+)\.(\d+) \(" + ApiShared.RUNTIME_INFORMATION.Replace("(", "").Replace(")", "") + @"\) UserPlatform/2\.3", httpRequestMessage.Headers.UserAgent.ToString()); } @@ -514,17 +514,17 @@ public void UnexpectedUserPlatformShouldNotThrow(string userPlatorm) [TestCase("Mono 5.11.0 ((HEAD/768f1b247c6)")] [TestCase("(")] [TestCase(")")] - public void MalformedUserAgentShouldNotThrow(string userAgent) + public void MalformedRuntimeInformationShouldNotThrow(string runtimeInformation) { - var prevAgent = ApiShared.USER_AGENT; - ApiShared.USER_AGENT = userAgent; + var prevAgent = ApiShared.RUNTIME_INFORMATION; + ApiShared.RUNTIME_INFORMATION = runtimeInformation; try { Assert.DoesNotThrow(() => CreateRequest("UserPlatform")); } finally { - ApiShared.USER_AGENT = prevAgent; + ApiShared.RUNTIME_INFORMATION = prevAgent; } } diff --git a/CloudinaryDotNet/ApiShared.Internal.cs b/CloudinaryDotNet/ApiShared.Internal.cs index 82c420d7..25e0f5ae 100644 --- a/CloudinaryDotNet/ApiShared.Internal.cs +++ b/CloudinaryDotNet/ApiShared.Internal.cs @@ -257,7 +257,9 @@ private static void AddCommentToUserAgent( return; } + // User-Agent's comment section is sensitive to brackets var normalizedComment = RemoveBracketsFrom(comment); + userAgentHeader.Add(new ProductInfoHeaderValue($"({normalizedComment})")); } @@ -478,7 +480,7 @@ private void PrePrepareRequestBody( var userAgentHeader = request.Headers.UserAgent; userAgentHeader.Add(new ProductInfoHeaderValue("CloudinaryDotNet", CloudinaryVersion.Full)); - AddCommentToUserAgent(userAgentHeader, USER_AGENT); + AddCommentToUserAgent(userAgentHeader, RUNTIME_INFORMATION); SetUserPlatform(userAgentHeader); byte[] authBytes = Encoding.ASCII.GetBytes(GetApiCredentials()); @@ -501,7 +503,6 @@ private void PrePrepareRequestBody( private void SetUserPlatform(HttpHeaderValueCollection userAgentHeader) { - Console.WriteLine($"UserPlatform: [{UserPlatform}] ======"); var up = UserPlatform?.Trim(); if (string.IsNullOrEmpty(up)) { diff --git a/CloudinaryDotNet/ApiShared.cs b/CloudinaryDotNet/ApiShared.cs index e6500907..c8fe8e60 100644 --- a/CloudinaryDotNet/ApiShared.cs +++ b/CloudinaryDotNet/ApiShared.cs @@ -69,9 +69,9 @@ public partial class ApiShared : ISignProvider public const string HTTP_BOUNDARY = "notrandomsequencetouseasboundary"; /// - /// User agent for cloudinary API requests. + /// Runtime information for cloudinary API requests. /// - public static string USER_AGENT = RuntimeInformation.FrameworkDescription; + public static string RUNTIME_INFORMATION = RuntimeInformation.FrameworkDescription; /// /// Whether to use a sub domain.