내용으로 건너뛰기

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

질문됨 2년 전458회 조회

1개 답변
0
수락된 답변

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.

답변함 2년 전

전문가

검토됨 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

관련 콘텐츠