Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
YomesInc committed Sep 20, 2021
1 parent faa37a1 commit a1e6328
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
10 changes: 5 additions & 5 deletions CloudinaryDotNet.Tests/Asset/UrlBuilderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand All @@ -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;
}
}

Expand Down
5 changes: 3 additions & 2 deletions CloudinaryDotNet/ApiShared.Internal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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})"));
}

Expand Down Expand Up @@ -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());
Expand All @@ -501,7 +503,6 @@ private void PrePrepareRequestBody(

private void SetUserPlatform(HttpHeaderValueCollection<ProductInfoHeaderValue> userAgentHeader)
{
Console.WriteLine($"UserPlatform: [{UserPlatform}] ======");
var up = UserPlatform?.Trim();
if (string.IsNullOrEmpty(up))
{
Expand Down
4 changes: 2 additions & 2 deletions CloudinaryDotNet/ApiShared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public partial class ApiShared : ISignProvider
public const string HTTP_BOUNDARY = "notrandomsequencetouseasboundary";

/// <summary>
/// User agent for cloudinary API requests.
/// Runtime information for cloudinary API requests.
/// </summary>
public static string USER_AGENT = RuntimeInformation.FrameworkDescription;
public static string RUNTIME_INFORMATION = RuntimeInformation.FrameworkDescription;

/// <summary>
/// Whether to use a sub domain.
Expand Down

0 comments on commit a1e6328

Please sign in to comment.