Skip to content

Commit 3056255

Browse files
committed
changed logic to use preexisiting search for m/ string
1 parent b5fc361 commit 3056255

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/aws-cpp-sdk-core/source/auth/signer/AWSAuthV4Signer.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -613,9 +613,13 @@ void AWSAuthV4Signer::UpdateUserAgentWithCredentialFeatures(Aws::Http::HttpReque
613613
}
614614

615615
const auto userAgent = request.GetHeaderValue(USER_AGENT);
616-
if (userAgent.find("m/") == Aws::String::npos) {
617-
AWS_LOGSTREAM_DEBUG(v4LogTag, "Custom User-Agent detected (no m/ prefix), skipping credential feature update");
618-
return;
616+
auto userAgentParsed = Aws::Utils::StringUtils::Split(userAgent, ' ');
617+
auto metricsSegment = std::find_if(userAgentParsed.begin(), userAgentParsed.end(),
618+
[](const Aws::String& value) { return value.find("m/") != Aws::String::npos; });
619+
620+
if (metricsSegment == userAgentParsed.end()) {
621+
AWS_LOGSTREAM_DEBUG(v4LogTag, "Custom User-Agent detected (no m/ prefix), skipping credential feature update");
622+
return;
619623
}
620624

621625
const auto features = context.GetUserAgentFeatures();
@@ -637,17 +641,7 @@ void AWSAuthV4Signer::UpdateUserAgentWithCredentialFeatures(Aws::Http::HttpReque
637641
return a + "," + b;
638642
});
639643

640-
auto userAgentParsed = Aws::Utils::StringUtils::Split(userAgent, ' ');
641-
auto metricsSegment = std::find_if(userAgentParsed.begin(), userAgentParsed.end(),
642-
[](const Aws::String& value) { return value.find("m/") != Aws::String::npos; });
643-
644-
if (metricsSegment != userAgentParsed.end()) {
645-
// Add new metrics to existing metrics section
646-
*metricsSegment = Aws::String{*metricsSegment + "," + credentialFeatures};
647-
} else {
648-
// No metrics section exists, add new one
649-
userAgentParsed.push_back("m/" + credentialFeatures);
650-
}
644+
*metricsSegment = Aws::String{*metricsSegment + "," + credentialFeatures};
651645

652646
// Reassemble all parts with spaces
653647
const auto newUserAgent = std::accumulate(std::next(userAgentParsed.begin()),

0 commit comments

Comments
 (0)