@@ -836,7 +836,7 @@ public void exchangeParameterizedType() throws Exception {
836
836
}
837
837
838
838
@ Test // SPR-15066
839
- public void requestInterceptorCanAddExistingHeaderValue () throws Exception {
839
+ public void requestInterceptorCanAddExistingHeaderValueWithoutBody () throws Exception {
840
840
ClientHttpRequestInterceptor interceptor = (request , body , execution ) -> {
841
841
request .getHeaders ().add ("MyHeader" , "MyInterceptorValue" );
842
842
return execution .execute (request , body );
@@ -861,4 +861,35 @@ public void requestInterceptorCanAddExistingHeaderValue() throws Exception {
861
861
verify (response ).close ();
862
862
}
863
863
864
+ @ Test // SPR-15066
865
+ public void requestInterceptorCanAddExistingHeaderValueWithBody () throws Exception {
866
+ ClientHttpRequestInterceptor interceptor = (request , body , execution ) -> {
867
+ request .getHeaders ().add ("MyHeader" , "MyInterceptorValue" );
868
+ return execution .execute (request , body );
869
+ };
870
+ template .setInterceptors (Collections .singletonList (interceptor ));
871
+
872
+ MediaType contentType = MediaType .TEXT_PLAIN ;
873
+ given (converter .canWrite (String .class , contentType )).willReturn (true );
874
+ given (requestFactory .createRequest (new URI ("http://example.com" ), HttpMethod .POST )).willReturn (request );
875
+ String helloWorld = "Hello World" ;
876
+ HttpHeaders requestHeaders = new HttpHeaders ();
877
+ given (request .getHeaders ()).willReturn (requestHeaders );
878
+ converter .write (helloWorld , contentType , request );
879
+ given (request .execute ()).willReturn (response );
880
+ given (errorHandler .hasError (response )).willReturn (false );
881
+ HttpStatus status = HttpStatus .OK ;
882
+ given (response .getStatusCode ()).willReturn (status );
883
+ given (response .getStatusText ()).willReturn (status .getReasonPhrase ());
884
+
885
+ HttpHeaders entityHeaders = new HttpHeaders ();
886
+ entityHeaders .setContentType (contentType );
887
+ entityHeaders .add ("MyHeader" , "MyEntityValue" );
888
+ HttpEntity <String > entity = new HttpEntity <>(helloWorld , entityHeaders );
889
+ template .exchange ("http://example.com" , HttpMethod .POST , entity , Void .class );
890
+ assertThat (requestHeaders .get ("MyHeader" ), contains ("MyEntityValue" , "MyInterceptorValue" ));
891
+
892
+ verify (response ).close ();
893
+ }
894
+
864
895
}
0 commit comments