Skip to content

Commit 746c30e

Browse files
committed
Add ProxyConfiguration support for UrlConnectionHttpClient, comments addressed
1 parent 3af41a0 commit 746c30e

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

.changes/next-release/feature-UrlConnectionHttpClient-f600f1e.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"category": "UrlConnectionHttpClient",
2+
"category": "URLConnection HTTP Client",
33
"contributor": "",
44
"type": "feature",
55
"description": "ProxyConfiguration support for UrlConnectionHttpClient."

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
@@ -214,7 +214,7 @@ private Optional<Proxy> determineProxy(URI uri) {
214214
if (isProxyEnabled() && isProxyHostIncluded(uri)) {
215215
return Optional.of(
216216
new Proxy(Proxy.Type.HTTP,
217-
new InetSocketAddress(this.proxyConfiguration.host(), this.proxyConfiguration.port())));
217+
InetSocketAddress.createUnresolved(this.proxyConfiguration.host(), this.proxyConfiguration.port())));
218218
}
219219
return Optional.empty();
220220
}

http-clients/url-connection-client/src/test/java/software/amazon/awssdk/http/urlconnection/UrlConnectionHttpClientWithProxyTest.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import software.amazon.awssdk.http.SdkHttpRequest;
4040
import software.amazon.awssdk.utils.AttributeMap;
4141

42-
public class UrlConnectionHttpClientWithProxyTest {
42+
class UrlConnectionHttpClientWithProxyTest {
4343
@RegisterExtension
4444
static WireMockExtension httpsWm = WireMockExtension.newInstance()
4545
.options(wireMockConfig().dynamicPort().dynamicHttpsPort())
@@ -53,7 +53,7 @@ public class UrlConnectionHttpClientWithProxyTest {
5353
private SdkHttpClient client;
5454

5555
@Test
56-
void Http_ProxyCallFrom_Https_Client() throws IOException {
56+
void Http_ProxyCallFrom_Https_Client_getsRejectedWith_404() throws IOException {
5757
httpWm.stubFor(requestMatching(
5858
request -> MatchResult.of(request.getUrl().contains(anyString()))
5959
).willReturn(aResponse()));
@@ -67,7 +67,7 @@ void Http_ProxyCallFrom_Https_Client() throws IOException {
6767
}
6868

6969
@Test
70-
void Http_ProxyCallFromWithDenyList_Https_Client() throws IOException {
70+
void Http_ProxyCallFromWithDenyList_HttpsClient_bypassesProxy_AndReturns_OK() throws IOException {
7171
httpWm.stubFor(requestMatching(
7272
request -> MatchResult.of(request.getUrl().contains(anyString()))
7373
).willReturn(aResponse()));
@@ -84,7 +84,7 @@ void Http_ProxyCallFromWithDenyList_Https_Client() throws IOException {
8484
}
8585

8686
@Test
87-
void emptyProxyConfig_Https_Client() throws IOException {
87+
void emptyProxyConfig_Https_Client_byPassesProxy_dReturns_OK() throws IOException {
8888
httpWm.stubFor(requestMatching(
8989
request -> MatchResult.of(request.getUrl().contains(anyString()))
9090
).willReturn(aResponse()));
@@ -99,7 +99,7 @@ void emptyProxyConfig_Https_Client() throws IOException {
9999
}
100100

101101
@Test
102-
void http_ProxyCallFrom_Http_Client() throws IOException {
102+
void http_ProxyCallFrom_Http_Client_isAcceptedByHttpProxy_AndReturns_OK() throws IOException {
103103

104104
httpWm.stubFor(requestMatching(
105105
request -> MatchResult.of(request.getUrl().contains(anyString()))
@@ -131,7 +131,6 @@ private HttpExecuteResponse makeRequestWithHttps_Client(SdkHttpClient httpClient
131131
return httpClient.prepareRequest(request).call();
132132
}
133133

134-
135134
private HttpExecuteResponse makeRequestWithHttp_Client(SdkHttpClient httpClient, WireMockRuntimeInfo wm) throws IOException {
136135
SdkHttpRequest httpRequest = SdkHttpFullRequest.builder()
137136
.method(SdkHttpMethod.GET)
@@ -146,7 +145,6 @@ private HttpExecuteResponse makeRequestWithHttp_Client(SdkHttpClient httpClient,
146145
return httpClient.prepareRequest(request).call();
147146
}
148147

149-
150148
private SdkHttpClient createHttpsClientForHttpServer(ProxyConfiguration proxyConfiguration) {
151149

152150
UrlConnectionHttpClient.Builder builder =
@@ -155,5 +153,4 @@ private SdkHttpClient createHttpsClientForHttpServer(ProxyConfiguration proxyCon
155153
attributeMap.put(TRUST_ALL_CERTIFICATES, true);
156154
return builder.buildWithDefaults(attributeMap.build());
157155
}
158-
159156
}

0 commit comments

Comments
 (0)