Skip to content

Commit

Permalink
Refactor ToUserAgentHeaderString and add new test
Browse files Browse the repository at this point in the history
Refactored the ToUserAgentHeaderString method in Marshaller.cs to use a switch statement instead of if-else statements, including a default case for converting requestRetryMode to lowercase. Removed Debug.Assert for retryMode and directly appended it to the StringBuilder object. Added LookForRequestRetryModeChanges test in StaticCheckTests.cs to verify the integrity of the RequestRetryMode enum.
  • Loading branch information
paulomorgado committed Aug 15, 2024
1 parent 57edba8 commit 58989b5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
17 changes: 10 additions & 7 deletions sdk/src/Core/Amazon.Runtime/Pipeline/Handlers/Marshaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ private static void SetUserAgentHeader(IRequestContext requestContext)
if (!string.IsNullOrEmpty(clientAppId))
sb.Append(" app/").Append(InternalSDKUtils.ReplaceInvalidUserAgentCharacters(clientAppId));

var retryMode = ToUserAgentHeaderString(requestContext.ClientConfig.RetryMode);
Debug.Assert(retryMode != requestContext.ClientConfig.RetryMode.ToString().ToLower(), "Invalid RetryMode string.");
sb.Append(" cfg/retry-mode#}").Append(retryMode);
sb.Append(" cfg/retry-mode#}").Append(ToUserAgentHeaderString(requestContext.ClientConfig.RetryMode));

sb.Append(" md/").Append(requestContext.IsAsync ? "ClientAsync" : "ClientSync");

Expand All @@ -143,10 +141,15 @@ private static void SetUserAgentHeader(IRequestContext requestContext)

private static string ToUserAgentHeaderString(RequestRetryMode requestRetryMode)
{
if (requestRetryMode == RequestRetryMode.Adaptive)
return "adaptive";
else
return "standard";
switch (requestRetryMode)
{
case RequestRetryMode.Standard:
return "standard";
case RequestRetryMode.Adaptive:
return "adaptive";
default:
return requestRetryMode.ToString().ToLowerInvariant();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,15 @@ public void EnsureCredentialProfileDetectorSetup()
// the properties are used at least once.
Assert.IsTrue(profileOptionsProperties.SetEquals(referencedProfileOptionsProperties));
}

[TestMethod]
public void LookForRequestRetryModeChanges()
{
var expectedHash = "2FC699DB6A4284C5D53F3B7FA4E64165576FD1F6AE458BC737AE503F06DFBE4C";
AssertExtensions.AssertEnumUnchanged(
typeof(RequestRetryMode),
expectedHash,
"The Amazon.Runtime.Internal.Marshaller.ToUserAgentHeaderString method implementation may need to be updated.");
}
}
}

0 comments on commit 58989b5

Please sign in to comment.