|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2018 the original author or authors. |
| 2 | + * Copyright 2002-2019 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
19 | 19 | import java.io.ByteArrayInputStream;
|
20 | 20 | import java.io.IOException;
|
21 | 21 | import java.net.URI;
|
| 22 | +import java.nio.charset.StandardCharsets; |
| 23 | +import java.util.Arrays; |
22 | 24 | import java.util.Collections;
|
23 | 25 | import java.util.EnumSet;
|
24 | 26 | import java.util.HashMap;
|
|
43 | 45 | import org.springframework.http.client.ClientHttpResponse;
|
44 | 46 | import org.springframework.http.converter.GenericHttpMessageConverter;
|
45 | 47 | import org.springframework.http.converter.HttpMessageConverter;
|
| 48 | +import org.springframework.http.converter.StringHttpMessageConverter; |
| 49 | +import org.springframework.util.StringUtils; |
46 | 50 | import org.springframework.web.util.DefaultUriTemplateHandler;
|
47 | 51 |
|
48 | 52 | import static org.hamcrest.MatcherAssert.assertThat;
|
@@ -878,4 +882,24 @@ public void requestInterceptorCanAddExistingHeaderValueWithBody() throws Excepti
|
878 | 882 | verify(response).close();
|
879 | 883 | }
|
880 | 884 |
|
| 885 | + @Test |
| 886 | + public void acceptHeaderValueShouldBeNotDuplicated() throws Exception { |
| 887 | + final StringHttpMessageConverter utf8HttpMessageConverter = new StringHttpMessageConverter(StandardCharsets.UTF_8); |
| 888 | + final StringHttpMessageConverter iso88591HttpMessageConverter = new StringHttpMessageConverter(StandardCharsets.ISO_8859_1); |
| 889 | + |
| 890 | + final RestTemplate multipleEncodingTemplate = new RestTemplate(Arrays.asList(utf8HttpMessageConverter, iso88591HttpMessageConverter)); |
| 891 | + multipleEncodingTemplate.setRequestFactory(requestFactory); |
| 892 | + given(requestFactory.createRequest(new URI("http://example.com"), GET)).willReturn(request); |
| 893 | + |
| 894 | + final HttpHeaders requestHeaders = new HttpHeaders(); |
| 895 | + given(request.getHeaders()).willReturn(requestHeaders); |
| 896 | + given(request.execute()).willReturn(response); |
| 897 | + |
| 898 | + final HttpHeaders responseHeaders = new HttpHeaders(); |
| 899 | + given(response.getHeaders()).willReturn(responseHeaders); |
| 900 | + |
| 901 | + multipleEncodingTemplate.getForObject("http://example.com", String.class); |
| 902 | + assertEquals("text/plain, */*", StringUtils.collectionToDelimitedString(request.getHeaders().get("accept"), ",")); |
| 903 | + } |
| 904 | + |
881 | 905 | }
|
0 commit comments