SPR-8809 - RestTemplate headers not sent when bufferRequestBody is false
This commit is contained in:
@@ -85,8 +85,9 @@ class InterceptingClientHttpRequest extends AbstractBufferingClientHttpRequest {
|
||||
|
||||
delegate.getHeaders().putAll(request.getHeaders());
|
||||
|
||||
FileCopyUtils.copy(body, delegate.getBody());
|
||||
|
||||
if (body.length > 0) {
|
||||
FileCopyUtils.copy(body, delegate.getBody());
|
||||
}
|
||||
return delegate.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,30 +73,38 @@ final class SimpleStreamingClientHttpRequest extends AbstractClientHttpRequest {
|
||||
else {
|
||||
this.connection.setChunkedStreamingMode(this.chunkSize);
|
||||
}
|
||||
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
|
||||
String headerName = entry.getKey();
|
||||
for (String headerValue : entry.getValue()) {
|
||||
this.connection.addRequestProperty(headerName, headerValue);
|
||||
}
|
||||
}
|
||||
this.connection.connect();
|
||||
writeHeaders(headers);
|
||||
this.connection.connect();
|
||||
this.body = this.connection.getOutputStream();
|
||||
}
|
||||
return new NonClosingOutputStream(this.body);
|
||||
}
|
||||
|
||||
@Override
|
||||
private void writeHeaders(HttpHeaders headers) {
|
||||
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
|
||||
String headerName = entry.getKey();
|
||||
for (String headerValue : entry.getValue()) {
|
||||
this.connection.addRequestProperty(headerName, headerValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ClientHttpResponse executeInternal(HttpHeaders headers) throws IOException {
|
||||
try {
|
||||
if (this.body != null) {
|
||||
this.body.close();
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
// ignore
|
||||
}
|
||||
return new SimpleClientHttpResponse(this.connection);
|
||||
}
|
||||
try {
|
||||
if (this.body != null) {
|
||||
this.body.close();
|
||||
}
|
||||
else {
|
||||
writeHeaders(headers);
|
||||
this.connection.connect();
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
// ignore
|
||||
}
|
||||
return new SimpleClientHttpResponse(this.connection);
|
||||
}
|
||||
|
||||
|
||||
private static class NonClosingOutputStream extends FilterOutputStream {
|
||||
|
||||
Reference in New Issue
Block a user