Skip to content

Commit 85cc8e9

Browse files
committed
Add 'Transfer-Encoding' header to the list of filtered headers
Resolves #1220
1 parent 1ecc876 commit 85cc8e9

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

spring-cloud-function-web/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@
6666
<artifactId>awaitility</artifactId>
6767
<scope>test</scope>
6868
</dependency>
69+
<dependency>
70+
<groupId>org.apache.httpcomponents.client5</groupId>
71+
<artifactId>httpclient5</artifactId>
72+
<scope>test</scope>
73+
</dependency>
6974
</dependencies>
7075

7176
<build>

spring-cloud-function-web/src/main/java/org/springframework/cloud/function/web/util/HeaderUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public final class HeaderUtils {
4545
static {
4646
IGNORED.add(MessageHeaders.ID, "");
4747
IGNORED.add(HttpHeaders.CONTENT_LENGTH, "0");
48+
IGNORED.add(HttpHeaders.TRANSFER_ENCODING, "*");
4849
// Headers that would typically be added by a downstream client
4950
REQUEST_ONLY.add(HttpHeaders.ACCEPT, "");
5051
REQUEST_ONLY.add(HttpHeaders.CONTENT_LENGTH, "");
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2024-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.function.web.function;
18+
19+
20+
import java.net.URI;
21+
import java.util.Locale;
22+
import java.util.function.Function;
23+
24+
import org.junit.jupiter.api.Test;
25+
26+
import org.springframework.boot.SpringApplication;
27+
import org.springframework.boot.autoconfigure.SpringBootApplication;
28+
import org.springframework.boot.test.web.client.TestRestTemplate;
29+
import org.springframework.context.ConfigurableApplicationContext;
30+
import org.springframework.context.annotation.Bean;
31+
import org.springframework.http.ResponseEntity;
32+
33+
import static org.assertj.core.api.Assertions.assertThat;
34+
35+
public class HeadersResponseMappingTests {
36+
37+
// see https://github.com/spring-cloud/spring-cloud-function/issues/1220
38+
@Test
39+
public void test_1220() throws Exception {
40+
ConfigurableApplicationContext context = SpringApplication.run(ApplicationConfiguration.class,
41+
"--server.port=0");
42+
TestRestTemplate testRestTemplate = new TestRestTemplate();
43+
String port = context.getEnvironment().getProperty("local.server.port");
44+
ResponseEntity<String> response = testRestTemplate.postForEntity(
45+
new URI("http://localhost:" + port + "/uppercase"), new Person("John", "Doe"), String.class);
46+
assertThat(response.getBody()).isEqualTo("JOHN");
47+
}
48+
49+
static record Person(String firstName, String lastName) {
50+
}
51+
52+
@SpringBootApplication
53+
protected static class ApplicationConfiguration {
54+
55+
@Bean
56+
public Function<Person, String> uppercase() {
57+
return s -> s.firstName().toUpperCase(Locale.ROOT);
58+
}
59+
60+
}
61+
}

0 commit comments

Comments
 (0)