diff --git a/spring-cloud-function-web/pom.xml b/spring-cloud-function-web/pom.xml index b46ace964..009f61704 100644 --- a/spring-cloud-function-web/pom.xml +++ b/spring-cloud-function-web/pom.xml @@ -66,6 +66,11 @@ awaitility test + + org.apache.httpcomponents.client5 + httpclient5 + test + diff --git a/spring-cloud-function-web/src/main/java/org/springframework/cloud/function/web/util/HeaderUtils.java b/spring-cloud-function-web/src/main/java/org/springframework/cloud/function/web/util/HeaderUtils.java index 6c3d37265..d4382fe6f 100644 --- a/spring-cloud-function-web/src/main/java/org/springframework/cloud/function/web/util/HeaderUtils.java +++ b/spring-cloud-function-web/src/main/java/org/springframework/cloud/function/web/util/HeaderUtils.java @@ -45,6 +45,7 @@ public final class HeaderUtils { static { IGNORED.add(MessageHeaders.ID, ""); IGNORED.add(HttpHeaders.CONTENT_LENGTH, "0"); + IGNORED.add(HttpHeaders.TRANSFER_ENCODING, "*"); // Headers that would typically be added by a downstream client REQUEST_ONLY.add(HttpHeaders.ACCEPT, ""); REQUEST_ONLY.add(HttpHeaders.CONTENT_LENGTH, ""); diff --git a/spring-cloud-function-web/src/test/java/org/springframework/cloud/function/web/function/HeadersResponseMappingTests.java b/spring-cloud-function-web/src/test/java/org/springframework/cloud/function/web/function/HeadersResponseMappingTests.java new file mode 100644 index 000000000..462c263ae --- /dev/null +++ b/spring-cloud-function-web/src/test/java/org/springframework/cloud/function/web/function/HeadersResponseMappingTests.java @@ -0,0 +1,61 @@ +/* + * Copyright 2024-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.function.web.function; + + +import java.net.URI; +import java.util.Locale; +import java.util.function.Function; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +public class HeadersResponseMappingTests { + + // see https://github.com/spring-cloud/spring-cloud-function/issues/1220 + @Test + public void test_1220() throws Exception { + ConfigurableApplicationContext context = SpringApplication.run(ApplicationConfiguration.class, + "--server.port=0"); + TestRestTemplate testRestTemplate = new TestRestTemplate(); + String port = context.getEnvironment().getProperty("local.server.port"); + ResponseEntity response = testRestTemplate.postForEntity( + new URI("http://localhost:" + port + "/uppercase"), new Person("John", "Doe"), String.class); + assertThat(response.getBody()).isEqualTo("JOHN"); + } + + static record Person(String firstName, String lastName) { + } + + @SpringBootApplication + protected static class ApplicationConfiguration { + + @Bean + public Function uppercase() { + return s -> s.firstName().toUpperCase(Locale.ROOT); + } + + } +}