Skip to content

Commit dbf3ea7

Browse files
committed
Moving USER_AGENT_SUFFIX value to the end of the user agent
1 parent 87d0d26 commit dbf3ea7

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/http/pipeline/stages/ApplyUserAgentStage.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,13 @@ public ApplyUserAgentStage(HttpClientDependencies dependencies) {
5050
@Override
5151
public SdkHttpFullRequest.Builder execute(SdkHttpFullRequest.Builder request, RequestExecutionContext context)
5252
throws Exception {
53-
String userAgent = getUserAgent(clientConfig, context.requestConfig().apiNames());
53+
StringBuilder userAgentBuilder = getUserAgent(clientConfig, context.requestConfig().apiNames());
54+
String userAgent = addUserAgentSuffix(userAgentBuilder, clientConfig);
5455
return request.putHeader(HEADER_USER_AGENT, userAgent);
5556
}
5657

57-
private String getUserAgent(SdkClientConfiguration config, List<ApiName> requestApiNames) {
58+
private StringBuilder getUserAgent(SdkClientConfiguration config, List<ApiName> requestApiNames) {
5859
String userDefinedPrefix = config.option(SdkAdvancedClientOption.USER_AGENT_PREFIX);
59-
String userDefinedSuffix = config.option(SdkAdvancedClientOption.USER_AGENT_SUFFIX);
60-
6160
String awsExecutionEnvironment = SdkSystemSetting.AWS_EXECUTION_ENV.getStringValue().orElse(null);
6261

6362
StringBuilder userAgent = new StringBuilder(StringUtils.trimToEmpty(userDefinedPrefix));
@@ -67,10 +66,6 @@ private String getUserAgent(SdkClientConfiguration config, List<ApiName> request
6766
userAgent.append(COMMA).append(systemUserAgent);
6867
}
6968

70-
if (!StringUtils.isEmpty(userDefinedSuffix)) {
71-
userAgent.append(COMMA).append(userDefinedSuffix.trim());
72-
}
73-
7469
if (!StringUtils.isEmpty(awsExecutionEnvironment)) {
7570
userAgent.append(SPACE).append(AWS_EXECUTION_ENV_PREFIX).append(awsExecutionEnvironment.trim());
7671
}
@@ -83,6 +78,20 @@ private String getUserAgent(SdkClientConfiguration config, List<ApiName> request
8378
userAgent.append(SPACE).append(requestUserAgent);
8479
}
8580

81+
return userAgent;
82+
}
83+
84+
/**
85+
* Only user agent suffix needs to be added in this method. Any other changes to user agent should be handled in
86+
* {@link #getUserAgent(SdkClientConfiguration, List)} method.
87+
*/
88+
private String addUserAgentSuffix(StringBuilder userAgent, SdkClientConfiguration config) {
89+
String userDefinedSuffix = config.option(SdkAdvancedClientOption.USER_AGENT_SUFFIX);
90+
91+
if (!StringUtils.isEmpty(userDefinedSuffix)) {
92+
userAgent.append(COMMA).append(userDefinedSuffix.trim());
93+
}
94+
8695
return userAgent.toString();
8796
}
8897
}

core/sdk-core/src/test/java/software/amazon/awssdk/core/http/AmazonHttpClientTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@
3333
import org.mockito.runners.MockitoJUnitRunner;
3434
import software.amazon.awssdk.core.Request;
3535
import software.amazon.awssdk.core.client.config.SdkAdvancedClientOption;
36+
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
3637
import software.amazon.awssdk.core.client.config.SdkClientOption;
3738
import software.amazon.awssdk.core.exception.SdkClientException;
38-
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
3939
import software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient;
4040
import software.amazon.awssdk.core.internal.http.timers.ClientExecutionAndRequestTimerTestUtils;
4141
import software.amazon.awssdk.http.AbortableCallable;
4242
import software.amazon.awssdk.http.ExecuteRequest;
4343
import software.amazon.awssdk.http.SdkHttpClient;
44-
import software.amazon.awssdk.http.SdkHttpFullRequest;
4544
import software.amazon.awssdk.http.SdkHttpFullResponse;
4645
import utils.HttpTestUtils;
4746
import utils.ValidSdkObjects;

0 commit comments

Comments
 (0)