Consistently call HttpURLConnection.setFixedLengthStreamingMode(long)

Issue: SPR-16404
This commit is contained in:
Juergen Hoeller 2018-01-20 14:29:40 +01:00
parent 142f1ab42f
commit 395c9bd723
2 changed files with 10 additions and 6 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -30,13 +30,15 @@ import org.springframework.util.StreamUtils;
import org.springframework.util.concurrent.ListenableFuture;
/**
* {@link org.springframework.http.client.ClientHttpRequest} implementation that uses
* standard Java facilities to execute streaming requests. Created via the {@link
* org.springframework.http.client.SimpleClientHttpRequestFactory}.
* {@link org.springframework.http.client.ClientHttpRequest} implementation
* that uses standard Java facilities to execute streaming requests. Created
* via the {@link org.springframework.http.client.SimpleClientHttpRequestFactory}.
*
* @author Arjen Poutsma
* @since 3.0
* @see org.springframework.http.client.SimpleClientHttpRequestFactory#createRequest
* @see org.springframework.http.client.support.AsyncHttpAccessor
* @see org.springframework.web.client.AsyncRestTemplate
* @deprecated as of Spring 5.0, with no direct replacement
*/
@Deprecated
@ -84,7 +86,7 @@ final class SimpleStreamingAsyncClientHttpRequest extends AbstractAsyncClientHtt
protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException {
if (this.body == null) {
if (this.outputStreaming) {
int contentLength = (int) headers.getContentLength();
long contentLength = headers.getContentLength();
if (contentLength >= 0) {
this.connection.setFixedLengthStreamingMode(contentLength);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -34,6 +34,8 @@ import org.springframework.util.StreamUtils;
* @author Arjen Poutsma
* @since 3.0
* @see SimpleClientHttpRequestFactory#createRequest(java.net.URI, HttpMethod)
* @see org.springframework.http.client.support.HttpAccessor
* @see org.springframework.web.client.RestTemplate
*/
final class SimpleStreamingClientHttpRequest extends AbstractClientHttpRequest {