Skip to content

Http Client made consistent with Default Proxy Configurations #4957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/next-release/bugfix-AWSCRTHTTPClient-cfe4870.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "AWS CRT HTTP Client",
"contributor": "",
"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 changes: 6 additions & 0 deletions .changes/next-release/bugfix-AWSSDKforJavav2-c277e61.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "AWS SDK for Java v2",
"contributor": "",
"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."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "Netty NIO Async HTTP Client",
"contributor": "",
"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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.awssdk.http.apache;

import org.apache.http.conn.HttpHostConnectException;
import software.amazon.awssdk.http.SdkHttpClient;
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
import software.amazon.awssdk.http.proxy.HttpClientDefaultProxyConfigTestSuite;
import java.net.ConnectException;

public class ApacheClientProxyConfigurationTest extends HttpClientDefaultProxyConfigTestSuite {

@Override
protected Class<? extends Exception> getProxyFailedExceptionType() {
return HttpHostConnectException.class;

}

@Override
protected Class<? extends Exception> getProxyFailedCauseExceptionType() {
return ConnectException.class;
}

@Override
protected boolean isSyncClient() {
return true;
}

@Override
protected SdkAsyncHttpClient createHttpClientWithDefaultProxy() {
throw new IllegalArgumentException("Async client is not supported for this test.");
}

@Override
protected SdkHttpClient createSyncHttpClientWithDefaultProxy() {
return ApacheHttpClient.create();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public class AwsCrtClientBuilderBase<BuilderT> {
private final AttributeMap.Builder standardOptions = AttributeMap.builder();
private Long readBufferSize;
private ProxyConfiguration proxyConfiguration;
private ProxyConfiguration proxyConfiguration = ProxyConfiguration.builder().build();
private ConnectionHealthConfiguration connectionHealthConfiguration;
private TcpKeepAliveConfiguration tcpKeepAliveConfiguration;
private Boolean postQuantumTlsEnabled;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.awssdk.http.crt;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import software.amazon.awssdk.http.SdkHttpClient;
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
import software.amazon.awssdk.http.proxy.HttpClientDefaultProxyConfigTestSuite;

public class AsyncCrtClientProxyConfigurationTest extends HttpClientDefaultProxyConfigTestSuite {
@Override
protected Class<? extends Exception> getProxyFailedExceptionType() {
return ExecutionException.class;
}

@Override
protected Class<? extends Exception> getProxyFailedCauseExceptionType() {
return IOException.class;
}

@Override
protected boolean isSyncClient() {
return false;
}

@Override
protected SdkAsyncHttpClient createHttpClientWithDefaultProxy() {
return AwsCrtAsyncHttpClient.create();
}

@Override
protected SdkHttpClient createSyncHttpClientWithDefaultProxy() {
throw new IllegalArgumentException("Sync client is not supported for this test.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.awssdk.http.crt;

import java.io.IOException;
import software.amazon.awssdk.crt.http.HttpException;
import software.amazon.awssdk.http.SdkHttpClient;
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
import software.amazon.awssdk.http.proxy.HttpClientDefaultProxyConfigTestSuite;

public class SyncCrtClientProxyConfigurationTest extends HttpClientDefaultProxyConfigTestSuite {

@Override
protected Class<? extends Exception> getProxyFailedExceptionType() {
return IOException.class;
}

@Override
protected Class<? extends Exception> getProxyFailedCauseExceptionType() {
return HttpException.class;
}

@Override
protected boolean isSyncClient() {
return true;
}

@Override
protected SdkAsyncHttpClient createHttpClientWithDefaultProxy() {
throw new UnsupportedOperationException("Async client is not supported for this test.");
}

@Override
protected SdkHttpClient createSyncHttpClientWithDefaultProxy() {
return AwsCrtHttpClient.create();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ private static final class DefaultBuilder implements Builder {
private Integer maxHttp2Streams;
private Http2Configuration http2Configuration;
private SslProvider sslProvider;
private ProxyConfiguration proxyConfiguration;
private ProxyConfiguration proxyConfiguration = ProxyConfiguration.builder().build();
private Boolean useNonBlockingDnsResolver;

private DefaultBuilder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private Bootstrap createBootstrap(URI poolKey) {


private boolean shouldUseProxyForHost(URI remoteAddr) {
if (proxyConfiguration == null) {
if (proxyConfiguration == null || proxyConfiguration.host() == null) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import java.net.ConnectException;
import java.util.concurrent.ExecutionException;
import software.amazon.awssdk.http.SdkHttpClient;
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
import software.amazon.awssdk.http.proxy.HttpClientDefaultProxyConfigTestSuite;

public class NettyClientProxyConfigurationTest extends HttpClientDefaultProxyConfigTestSuite {
@Override
protected boolean isSyncClient() {
return false;
}

@Override
protected SdkAsyncHttpClient createHttpClientWithDefaultProxy() {
return NettyNioAsyncHttpClient.create();
}

@Override
protected SdkHttpClient createSyncHttpClientWithDefaultProxy() {
throw new IllegalArgumentException("Sync client is not supported for this test.");
}

@Override
protected Class<? extends Exception> getProxyFailedExceptionType() {
return ExecutionException.class;
}

@Override
protected Class<? extends Exception> getProxyFailedCauseExceptionType() {
return ConnectException.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ public interface Builder extends SdkHttpClient.Builder<UrlConnectionHttpClient.B

private static final class DefaultBuilder implements Builder {
private final AttributeMap.Builder standardOptions = AttributeMap.builder();
private ProxyConfiguration proxyConfiguration;
private ProxyConfiguration proxyConfiguration = ProxyConfiguration.builder().build();

private DefaultBuilder() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.awssdk.http.urlconnection;

import java.io.IOException;
import software.amazon.awssdk.http.SdkHttpClient;
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
import software.amazon.awssdk.http.proxy.HttpClientDefaultProxyConfigTestSuite;

public class UrlClientProxyConfigurationTest extends HttpClientDefaultProxyConfigTestSuite {
@Override
protected boolean isSyncClient() {
return true;
}

@Override
protected SdkAsyncHttpClient createHttpClientWithDefaultProxy() {
throw new UnsupportedOperationException("Async client is not supported for this test.");
}

@Override
protected SdkHttpClient createSyncHttpClientWithDefaultProxy() {
return UrlConnectionHttpClient.create();
}

@Override
protected Class<? extends Exception> getProxyFailedExceptionType() {
return IOException.class;
}

@Override
protected Class<? extends Exception> getProxyFailedCauseExceptionType() {
return null;
}
}
Loading