use of software.amazon.awssdk.http.Header.CONTENT_LENGTH in project aws-sdk-java-v2 by aws.
the class UrlConnectionHttpClient method createAndConfigureConnection.
private HttpURLConnection createAndConfigureConnection(HttpExecuteRequest request) {
HttpURLConnection connection = connectionFactory.createConnection(request.httpRequest().getUri());
request.httpRequest().headers().forEach((key, values) -> values.forEach(value -> connection.setRequestProperty(key, value)));
invokeSafely(() -> connection.setRequestMethod(request.httpRequest().method().name()));
if (request.contentStreamProvider().isPresent()) {
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);
request.httpRequest().firstMatchingHeader(CONTENT_LENGTH).map(Long::parseLong).ifPresent(connection::setFixedLengthStreamingMode);
return connection;
}
Aggregations