Skip to content

Commit 53f190b

Browse files
committed
Handle HttpURLConnection switching GET->POST and not supporting PATCH
1 parent 12b2fc6 commit 53f190b

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

Diff for: http-clients/url-connection-client/src/test/java/software/amazon/awssdk/http/urlconnection/UrlConnectionHttpClientDefaultWireMockTest.java

+21
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@
1515

1616
package software.amazon.awssdk.http.urlconnection;
1717

18+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
19+
20+
import java.net.ProtocolException;
1821
import javax.net.ssl.HttpsURLConnection;
1922
import javax.net.ssl.SSLSocketFactory;
23+
import org.junit.Test;
2024
import org.junit.jupiter.api.AfterEach;
2125
import software.amazon.awssdk.http.SdkHttpClient;
2226
import software.amazon.awssdk.http.SdkHttpClientDefaultTestSuite;
27+
import software.amazon.awssdk.http.SdkHttpMethod;
2328

2429
public class UrlConnectionHttpClientDefaultWireMockTest extends SdkHttpClientDefaultTestSuite {
2530

@@ -32,4 +37,20 @@ protected SdkHttpClient createSdkHttpClient() {
3237
public void reset() {
3338
HttpsURLConnection.setDefaultSSLSocketFactory((SSLSocketFactory) SSLSocketFactory.getDefault());
3439
}
40+
41+
@Test
42+
@Override
43+
public void supportsRequestBodyOnGetRequest() throws Exception {
44+
// HttpURLConnection is hard-coded to switch GET requests with a body to POST requests, in #getOutputStream0.
45+
testForResponseCode(200, SdkHttpMethod.GET, SdkHttpMethod.POST, true);
46+
}
47+
48+
@Test
49+
@Override
50+
public void supportsRequestBodyOnPatchRequest() {
51+
// HttpURLConnection does not support PATCH requests.
52+
assertThatThrownBy(super::supportsRequestBodyOnPatchRequest)
53+
.hasRootCauseInstanceOf(ProtocolException.class)
54+
.hasRootCauseMessage("Invalid HTTP method: PATCH");
55+
}
3556
}

Diff for: test/http-client-tests/src/main/java/software/amazon/awssdk/http/SdkHttpClientDefaultTestSuite.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,14 @@ private void testForResponseCode(int returnCode) throws Exception {
143143
testForResponseCode(returnCode, SdkHttpMethod.POST, true);
144144
}
145145

146-
private void testForResponseCode(int returnCode, SdkHttpMethod method, boolean includeBody) throws Exception {
146+
protected void testForResponseCode(int returnCode, SdkHttpMethod method, boolean includeBody) throws Exception {
147+
testForResponseCode(returnCode, method, method, includeBody);
148+
}
149+
150+
protected void testForResponseCode(int returnCode,
151+
SdkHttpMethod method,
152+
SdkHttpMethod expectedMethod,
153+
boolean includeBody) throws Exception {
147154
SdkHttpClient client = createSdkHttpClient();
148155

149156
stubForMockRequest(returnCode);
@@ -156,7 +163,7 @@ private void testForResponseCode(int returnCode, SdkHttpMethod method, boolean i
156163
.build())
157164
.call();
158165

159-
validateResponse(rsp, returnCode, method, includeBody);
166+
validateResponse(rsp, returnCode, expectedMethod, includeBody);
160167
}
161168

162169
protected void testForResponseCodeUsingHttps(SdkHttpClient client, int returnCode) throws Exception {

0 commit comments

Comments
 (0)