Skip to content

Commit efa4396

Browse files
committed
Review comments
1 parent bdeaea3 commit efa4396

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

http-clients/apache5-client/src/main/java/software/amazon/awssdk/http/apache5/Apache5HttpClient.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,6 @@ public final class Apache5HttpClient implements SdkHttpClient {
132132

133133
private static final String CLIENT_NAME = "Apache5Preview";
134134

135-
// The global SdkHttpConfigurationOption.DEFAULT_CONNECTION_TIME_TO_LIVE is defined as Duration.ZERO to indicate infinite
136-
// TTL. However, Apache 5.x defines 0 as immediate expiry. Shadow this default to -1 instead so that we still default to
137-
// infinite TTL when not explicitly configured.
138-
private static final AttributeMap APACHE5_HTTP_DEFAULTS = AttributeMap.builder()
139-
.put(SdkHttpConfigurationOption.CONNECTION_TIME_TO_LIVE, Duration.ofMillis(-1))
140-
.build();
141-
142135
private static final Logger log = Logger.loggerFor(Apache5HttpClient.class);
143136
private static final HostnameVerifier DEFAULT_HOSTNAME_VERIFIER = new DefaultHostnameVerifier();
144137
private final Apache5HttpRequestFactory apacheHttpRequestFactory = new Apache5HttpRequestFactory();
@@ -743,10 +736,8 @@ public void setAuthSchemeProviderRegistry(Registry<AuthSchemeFactory> authScheme
743736

744737
@Override
745738
public SdkHttpClient buildWithDefaults(AttributeMap serviceDefaults) {
746-
AttributeMap resolvedOptions = standardOptions.build()
747-
.merge(serviceDefaults)
748-
.merge(APACHE5_HTTP_DEFAULTS)
749-
.merge(SdkHttpConfigurationOption.GLOBAL_HTTP_DEFAULTS);
739+
AttributeMap resolvedOptions = standardOptions.build().merge(serviceDefaults).merge(
740+
SdkHttpConfigurationOption.GLOBAL_HTTP_DEFAULTS);
750741
return new Apache5HttpClient(this, resolvedOptions);
751742
}
752743
}
@@ -778,7 +769,11 @@ private static ConnectionConfig getConnectionConfig(AttributeMap standardOptions
778769
.setSocketTimeout(Timeout.ofMilliseconds(
779770
standardOptions.get(SdkHttpConfigurationOption.READ_TIMEOUT).toMillis()));
780771
Duration connectionTtl = standardOptions.get(SdkHttpConfigurationOption.CONNECTION_TIME_TO_LIVE);
781-
connectionConfigBuilder.setTimeToLive(TimeValue.ofMilliseconds(connectionTtl.toMillis()));
772+
// Only accept positive values.
773+
// Note: TTL=0 is infinite in 4.x vs immediate expiration in 5.x
774+
if (!connectionTtl.isNegative() && !connectionTtl.isZero()) {
775+
connectionConfigBuilder.setTimeToLive(TimeValue.ofMilliseconds(connectionTtl.toMillis()));
776+
}
782777
return connectionConfigBuilder.build();
783778
}
784779

http-clients/apache5-client/src/test/java/software/amazon/awssdk/http/apache5/ConnectionTtlTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void execute_ttlNegative_connectionNotClosed() throws Exception {
110110
}
111111

112112
@Test
113-
public void execute_ttlIsZero_connectionClosed() throws Exception {
113+
public void execute_ttlIsZero_connectionNotClosed() throws Exception {
114114
TestTlsSocketStrategy socketStrategy = TestTlsSocketStrategy.create();
115115

116116
apache5 = Apache5HttpClient.builder()
@@ -123,7 +123,7 @@ public void execute_ttlIsZero_connectionClosed() throws Exception {
123123
doGetCall(apache5);
124124

125125
List<SSLSocket> sockets = socketStrategy.getCreatedSockets();
126-
assertThat(sockets).hasSize(2);
126+
assertThat(sockets).hasSize(1);
127127
}
128128

129129
@Test

0 commit comments

Comments
 (0)