SPR-8809 - RestTemplate headers not sent when bufferRequestBody is false
This commit is contained in:
parent
951514a576
commit
91c14bd1fe
|
|
@ -85,9 +85,8 @@ class InterceptingClientHttpRequest extends AbstractBufferingClientHttpRequest {
|
|||
|
||||
delegate.getHeaders().putAll(request.getHeaders());
|
||||
|
||||
if (body.length > 0) {
|
||||
FileCopyUtils.copy(body, delegate.getBody());
|
||||
}
|
||||
|
||||
return delegate.execute();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,14 +16,18 @@
|
|||
|
||||
package org.springframework.http.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpRequest;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
|
@ -37,6 +41,36 @@ public class StreamingSimpleHttpRequestFactoryTests extends AbstractHttpRequestF
|
|||
return factory;
|
||||
}
|
||||
|
||||
// SPR-8809
|
||||
@Test
|
||||
public void interceptor() throws Exception {
|
||||
final String headerName = "MyHeader";
|
||||
final String headerValue = "MyValue";
|
||||
ClientHttpRequestInterceptor interceptor = new ClientHttpRequestInterceptor() {
|
||||
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
|
||||
throws IOException {
|
||||
request.getHeaders().add(headerName, headerValue);
|
||||
return execution.execute(request, body);
|
||||
}
|
||||
};
|
||||
InterceptingClientHttpRequestFactory factory = new InterceptingClientHttpRequestFactory(createRequestFactory(),
|
||||
Collections.singletonList(interceptor));
|
||||
|
||||
ClientHttpResponse response = null;
|
||||
try {
|
||||
ClientHttpRequest request = factory.createRequest(new URI(baseUrl + "/echo"), HttpMethod.POST);
|
||||
response = request.execute();
|
||||
assertEquals("Invalid response status", HttpStatus.OK, response.getStatusCode());
|
||||
HttpHeaders responseHeaders = response.getHeaders();
|
||||
assertEquals("Custom header invalid", headerValue, responseHeaders.getFirst(headerName));
|
||||
}
|
||||
finally {
|
||||
if (response != null) {
|
||||
response.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void largeFileUpload() throws Exception {
|
||||
|
|
|
|||
Loading…
Reference in New Issue