Skip to content

Lower memory consumption by streaming request data #2848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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,6 @@
{
"category": "URL Connection Http Client",
"contributor": "rtyley",
"type": "feature",
"description": "Lower memory consumption for HTTP requests by enabling fixed-length streaming mode."
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package software.amazon.awssdk.http.urlconnection;

import static software.amazon.awssdk.http.Header.CONTENT_LENGTH;
import static software.amazon.awssdk.http.HttpStatusFamily.CLIENT_ERROR;
import static software.amazon.awssdk.http.HttpStatusFamily.SERVER_ERROR;
import static software.amazon.awssdk.utils.FunctionalUtils.invokeSafely;
Expand Down Expand Up @@ -140,6 +141,9 @@ private HttpURLConnection createAndConfigureConnection(HttpExecuteRequest reques
// See: https://github.com/aws/aws-sdk-java-v2/issues/975
connection.setInstanceFollowRedirects(false);

request.httpRequest().firstMatchingHeader(CONTENT_LENGTH).map(Long::parseLong)
.ifPresent(connection::setFixedLengthStreamingMode);

return connection;
}

Expand Down