Skip to content

Commit 51c1657

Browse files
authored
Http Client made consistent with Default Proxy Configurations (#4957)
* Http Client made consistent with Default Proxy Configurations * made changes for URL client * Updated test case Name * Updated comments related to test cases * Updated change logs
1 parent 0d08273 commit 51c1657

File tree

13 files changed

+609
-4
lines changed

13 files changed

+609
-4
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "AWS CRT HTTP Client",
4+
"contributor": "",
5+
"description": "Addressing Issue [#4745](https://github.com/aws/aws-sdk-java-v2/issues/4745) , Netty and CRT clients' default proxy settings have been made consistent with the Apache client, now using environment and system property settings by default.\\n To disable the use of environment variables and system properties by default, set useSystemPropertyValue(false) and useEnvironmentVariablesValues(false) in ProxyConfigurations."
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "AWS SDK for Java v2",
4+
"contributor": "",
5+
"description": "Addressing Issue [#4745](https://github.com/aws/aws-sdk-java-v2/issues/4745) , Netty and CRT clients' default proxy settings have been made consistent with the Apache client, now using environment and system property settings by default.\n To disable the use of environment variables and system properties by default, set useSystemPropertyValue(false) and useEnvironmentVariablesValues(false) in ProxyConfigurations."
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "Netty NIO Async HTTP Client",
4+
"contributor": "",
5+
"description": "Addressing Issue [#4745](https://github.com/aws/aws-sdk-java-v2/issues/4745) , Netty and CRT clients' default proxy settings have been made consistent with the Apache client, now using environment and system property settings by default.\\n To disable the use of environment variables and system properties by default, set useSystemPropertyValue(false) and useEnvironmentVariablesValues(false) in ProxyConfigurations"
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.http.apache;
17+
18+
import org.apache.http.conn.HttpHostConnectException;
19+
import software.amazon.awssdk.http.SdkHttpClient;
20+
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
21+
import software.amazon.awssdk.http.proxy.HttpClientDefaultProxyConfigTestSuite;
22+
import java.net.ConnectException;
23+
24+
public class ApacheClientProxyConfigurationTest extends HttpClientDefaultProxyConfigTestSuite {
25+
26+
@Override
27+
protected Class<? extends Exception> getProxyFailedExceptionType() {
28+
return HttpHostConnectException.class;
29+
30+
}
31+
32+
@Override
33+
protected Class<? extends Exception> getProxyFailedCauseExceptionType() {
34+
return ConnectException.class;
35+
}
36+
37+
@Override
38+
protected boolean isSyncClient() {
39+
return true;
40+
}
41+
42+
@Override
43+
protected SdkAsyncHttpClient createHttpClientWithDefaultProxy() {
44+
throw new IllegalArgumentException("Async client is not supported for this test.");
45+
}
46+
47+
@Override
48+
protected SdkHttpClient createSyncHttpClientWithDefaultProxy() {
49+
return ApacheHttpClient.create();
50+
}
51+
52+
}

http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/internal/AwsCrtClientBuilderBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
public class AwsCrtClientBuilderBase<BuilderT> {
3030
private final AttributeMap.Builder standardOptions = AttributeMap.builder();
3131
private Long readBufferSize;
32-
private ProxyConfiguration proxyConfiguration;
32+
private ProxyConfiguration proxyConfiguration = ProxyConfiguration.builder().build();
3333
private ConnectionHealthConfiguration connectionHealthConfiguration;
3434
private TcpKeepAliveConfiguration tcpKeepAliveConfiguration;
3535
private Boolean postQuantumTlsEnabled;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.http.crt;
17+
18+
import java.io.IOException;
19+
import java.util.concurrent.ExecutionException;
20+
import software.amazon.awssdk.http.SdkHttpClient;
21+
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
22+
import software.amazon.awssdk.http.proxy.HttpClientDefaultProxyConfigTestSuite;
23+
24+
public class AsyncCrtClientProxyConfigurationTest extends HttpClientDefaultProxyConfigTestSuite {
25+
@Override
26+
protected Class<? extends Exception> getProxyFailedExceptionType() {
27+
return ExecutionException.class;
28+
}
29+
30+
@Override
31+
protected Class<? extends Exception> getProxyFailedCauseExceptionType() {
32+
return IOException.class;
33+
}
34+
35+
@Override
36+
protected boolean isSyncClient() {
37+
return false;
38+
}
39+
40+
@Override
41+
protected SdkAsyncHttpClient createHttpClientWithDefaultProxy() {
42+
return AwsCrtAsyncHttpClient.create();
43+
}
44+
45+
@Override
46+
protected SdkHttpClient createSyncHttpClientWithDefaultProxy() {
47+
throw new IllegalArgumentException("Sync client is not supported for this test.");
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.http.crt;
17+
18+
import java.io.IOException;
19+
import software.amazon.awssdk.crt.http.HttpException;
20+
import software.amazon.awssdk.http.SdkHttpClient;
21+
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
22+
import software.amazon.awssdk.http.proxy.HttpClientDefaultProxyConfigTestSuite;
23+
24+
public class SyncCrtClientProxyConfigurationTest extends HttpClientDefaultProxyConfigTestSuite {
25+
26+
@Override
27+
protected Class<? extends Exception> getProxyFailedExceptionType() {
28+
return IOException.class;
29+
}
30+
31+
@Override
32+
protected Class<? extends Exception> getProxyFailedCauseExceptionType() {
33+
return HttpException.class;
34+
}
35+
36+
@Override
37+
protected boolean isSyncClient() {
38+
return true;
39+
}
40+
41+
@Override
42+
protected SdkAsyncHttpClient createHttpClientWithDefaultProxy() {
43+
throw new UnsupportedOperationException("Async client is not supported for this test.");
44+
}
45+
46+
@Override
47+
protected SdkHttpClient createSyncHttpClientWithDefaultProxy() {
48+
return AwsCrtHttpClient.create();
49+
}
50+
}

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/NettyNioAsyncHttpClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ private static final class DefaultBuilder implements Builder {
501501
private Integer maxHttp2Streams;
502502
private Http2Configuration http2Configuration;
503503
private SslProvider sslProvider;
504-
private ProxyConfiguration proxyConfiguration;
504+
private ProxyConfiguration proxyConfiguration = ProxyConfiguration.builder().build();
505505
private Boolean useNonBlockingDnsResolver;
506506

507507
private DefaultBuilder() {

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/AwaitCloseChannelPoolMap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ private Bootstrap createBootstrap(URI poolKey) {
186186

187187

188188
private boolean shouldUseProxyForHost(URI remoteAddr) {
189-
if (proxyConfiguration == null) {
189+
if (proxyConfiguration == null || proxyConfiguration.host() == null) {
190190
return false;
191191
}
192192

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
import java.net.ConnectException;
17+
import java.util.concurrent.ExecutionException;
18+
import software.amazon.awssdk.http.SdkHttpClient;
19+
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
20+
import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
21+
import software.amazon.awssdk.http.proxy.HttpClientDefaultProxyConfigTestSuite;
22+
23+
public class NettyClientProxyConfigurationTest extends HttpClientDefaultProxyConfigTestSuite {
24+
@Override
25+
protected boolean isSyncClient() {
26+
return false;
27+
}
28+
29+
@Override
30+
protected SdkAsyncHttpClient createHttpClientWithDefaultProxy() {
31+
return NettyNioAsyncHttpClient.create();
32+
}
33+
34+
@Override
35+
protected SdkHttpClient createSyncHttpClientWithDefaultProxy() {
36+
throw new IllegalArgumentException("Sync client is not supported for this test.");
37+
}
38+
39+
@Override
40+
protected Class<? extends Exception> getProxyFailedExceptionType() {
41+
return ExecutionException.class;
42+
}
43+
44+
@Override
45+
protected Class<? extends Exception> getProxyFailedCauseExceptionType() {
46+
return ConnectException.class;
47+
}
48+
}

http-clients/url-connection-client/src/main/java/software/amazon/awssdk/http/urlconnection/UrlConnectionHttpClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ public interface Builder extends SdkHttpClient.Builder<UrlConnectionHttpClient.B
496496

497497
private static final class DefaultBuilder implements Builder {
498498
private final AttributeMap.Builder standardOptions = AttributeMap.builder();
499-
private ProxyConfiguration proxyConfiguration;
499+
private ProxyConfiguration proxyConfiguration = ProxyConfiguration.builder().build();
500500

501501
private DefaultBuilder() {
502502
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.http.urlconnection;
17+
18+
import java.io.IOException;
19+
import software.amazon.awssdk.http.SdkHttpClient;
20+
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
21+
import software.amazon.awssdk.http.proxy.HttpClientDefaultProxyConfigTestSuite;
22+
23+
public class UrlClientProxyConfigurationTest extends HttpClientDefaultProxyConfigTestSuite {
24+
@Override
25+
protected boolean isSyncClient() {
26+
return true;
27+
}
28+
29+
@Override
30+
protected SdkAsyncHttpClient createHttpClientWithDefaultProxy() {
31+
throw new UnsupportedOperationException("Async client is not supported for this test.");
32+
}
33+
34+
@Override
35+
protected SdkHttpClient createSyncHttpClientWithDefaultProxy() {
36+
return UrlConnectionHttpClient.create();
37+
}
38+
39+
@Override
40+
protected Class<? extends Exception> getProxyFailedExceptionType() {
41+
return IOException.class;
42+
}
43+
44+
@Override
45+
protected Class<? extends Exception> getProxyFailedCauseExceptionType() {
46+
return null;
47+
}
48+
}

0 commit comments

Comments
 (0)