How to direct HTTP requests using AWS CRT HTTP Client through proxy?

0

I am using the AWS CRT HTTP Client in the AWS SDK for Java 2.x, and I do not see requests directed to my local proxy. I am creating the request via the following (Java 11) code:

private static final SdkHttpClient httpClient = AwsCrtHttpClient.builder()
        .proxyConfiguration(ProxyConfiguration.builder().host("localhost").port(9001).build())
        .build();
SdkHttpRequest.Builder sdkHttpRequestBuilder;
// Conditional build logic removed
sdkHttpRequestBuilder = SdkHttpRequest.builder().uri(new URI(uri)).method(method);
SdkHttpRequest sdkHttpRequest = sdkHttpRequestBuilder
        .appendHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType())
        .build();
HttpExecuteResponse response = httpClient.prepareRequest(HttpExecuteRequest.builder().request(sdkHttpRequest).build()).call();

Despite the changes I make to the proxyConfiguration argument, I can't get these requests proxied. What am I doing wrong as I try to generate these requests? I am using aws-crt-client version 2.27.9.

The most relevant AWS documentation regarding this proxy configuration is found here: https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/http-configuration-crt.html#http-config-crt-proxy-ex

asked 2 months ago39 views
1 Answer
0
Accepted Answer

There was no issue with the client's proxy. This turned out to be a conflict with the default proxy settings used by Hoverfly.

The solution was to set the proxyLocalHost flag in the Hoverfly configuration to true. That's because the client's builder logic in the AWS CRT HTTP Client was reading Hoverfly's default values for the environment variable "http.nonProxyHosts" and then setting the client's proxy configuration to null with its builder logic. The workaround was to modify the Hoverfly configuration to set the proxyLocalHost flag to true like the following:

@HoverflyCore(config = @HoverflyConfig(proxyLocalHost = true))
@ExtendWith(HoverflyExtension.class)
class MyTest {
// ...

This sets the proxyLocalHost environment variable to "", and it allows for the default AWS CRT HTTP Client to proxy to localhost.

answered 2 months ago
profile picture
EXPERT
reviewed a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions