mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Fix HttpUrlConnection DELETE without body
The following commit allowed HTTP DELETE with body: https://github.com/spring-projects/spring-framework/commit/584b831bb9390a49c791d180d023e3a585203215 However it broke buffered requests even without a body since JDK 1.6 and 1.7 do not support calls to getOutputStream with HTTP DELETE. This commit set the doOutput flag back to false if the actual buffered body is 0 length. Issue: SPR-12361
This commit is contained in:
+4
@@ -78,6 +78,10 @@ final class SimpleBufferingAsyncClientHttpRequest extends AbstractBufferingAsync
|
||||
@Override
|
||||
public ClientHttpResponse call() throws Exception {
|
||||
SimpleBufferingClientHttpRequest.addHeaders(connection, headers);
|
||||
// JDK < 1.8 doesn't support getOutputStream with HTTP DELETE
|
||||
if (HttpMethod.DELETE.equals(getMethod()) && bufferedOutput.length == 0) {
|
||||
connection.setDoOutput(false);
|
||||
}
|
||||
if (connection.getDoOutput() && outputStreaming) {
|
||||
connection.setFixedLengthStreamingMode(bufferedOutput.length);
|
||||
}
|
||||
|
||||
+6
@@ -26,6 +26,7 @@ import java.util.Map;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -69,6 +70,11 @@ final class SimpleBufferingClientHttpRequest extends AbstractBufferingClientHttp
|
||||
protected ClientHttpResponse executeInternal(HttpHeaders headers, byte[] bufferedOutput) throws IOException {
|
||||
addHeaders(this.connection, headers);
|
||||
|
||||
// JDK < 1.8 doesn't support getOutputStream with HTTP DELETE
|
||||
if (HttpMethod.DELETE.equals(getMethod()) && bufferedOutput.length == 0) {
|
||||
this.connection.setDoOutput(false);
|
||||
}
|
||||
|
||||
if (this.connection.getDoOutput() && this.outputStreaming) {
|
||||
this.connection.setFixedLengthStreamingMode(bufferedOutput.length);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user