SPR-8809 - RestTemplate headers not sent when bufferRequestBody is false

This commit is contained in:
Arjen Poutsma
2011-12-02 11:29:47 +00:00
parent 9f98f77c3e
commit 53cb529162
4 changed files with 43 additions and 40 deletions

View File

@@ -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();
}
}

View File

@@ -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 {