Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"category": "URLConnection HTTP Client",
"type": "bugfix",
"description": "Disable following redirects automatically since doing so causes SDK response handling to fail"
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ private HttpURLConnection createAndConfigureConnection(HttpExecuteRequest reques
connection.setDoOutput(true);
}

// Disable following redirects since it breaks SDK error handling and matches Apache.
// See: https://github.com/aws/aws-sdk-java-v2/issues/975
connection.setInstanceFollowRedirects(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment why we do this?


return connection;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -129,8 +130,15 @@ protected void testForResponseCodeUsingHttps(SdkHttpClient client, int returnCod
}

private void stubForMockRequest(int returnCode) {
stubFor(any(urlPathEqualTo("/")).willReturn(
aResponse().withStatus(returnCode).withHeader("Some-Header", "With Value").withBody("hello")));
ResponseDefinitionBuilder responseBuilder = aResponse().withStatus(returnCode)
.withHeader("Some-Header", "With Value")
.withBody("hello");

if (returnCode >= 300 && returnCode <= 399) {
responseBuilder.withHeader("Location", "Some New Location");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually exercise this code path?

Copy link
Contributor Author

@abrooksv abrooksv Jan 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, supportsResponseCode301 and supportsResponseCode302 both trigger it.

supportsResponseCode302 -> testForResponseCode -> stubForMockRequest

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without disable leads to test failure:

java.lang.NullPointerException: delegate must not be null.

	at software.amazon.awssdk.utils.Validate.paramNotNull(Validate.java:118)
	at software.amazon.awssdk.http.AbortableInputStream.<init>(AbortableInputStream.java:35)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 awesome that you added a base-test for this so that we catch it for other implementations!


stubFor(any(urlPathEqualTo("/")).willReturn(responseBuilder));
}

private void validateResponse(HttpExecuteResponse response, int returnCode) throws IOException {
Expand Down