Skip to content

spring-cloud-starter-function-web adds multiple Transfer-Encoding headers in the response. #1220

Closed
@matthew-js-porter

Description

@matthew-js-porter

Describe the bug
spring-cloud-starter-function-web adds multiple Transfer-Encoding headers in the response. This will cause issues when using Apache HTTP Client to invoke the function. see: spring-projects/spring-boot#43547

Sample

  1. Generate a 3.4.0 project from https://start.spring.io/
  2. add Dependency Management for Spring Cloud
	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-dependencies</artifactId>
				<version>2024.0.0</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>
  1. add spring-cloud-starter-function-web
<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-function-web</artifactId>
</dependency>
  1. Create function handler
    FunctionHandler.java
@Component
public class FunctionHandler implements Function<Person, String> {

    @Override
    public String apply(final Person person) {
        return "Hello %s %s".formatted(person.firstName(), person.lastName());
    }
}

Person.java

public record Person(String firstName, String lastName) {}
  1. Create Test
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class ApacheTestRestTemplateApplicationTests {

	@BeforeAll
	static void beforeAll() {
		System.setProperty("jdk.httpclient.HttpClient.log","all");
	}

	@Autowired
	private TestRestTemplate testRestTemplate;

	@Test
	void saysHello() {
		final ResponseEntity<String> response = testRestTemplate.postForEntity("/", new Person("First", "Last"), String.class);
		System.out.println(response.getHeaders());
		assertThat(response.getBody()).isEqualTo("Hello First Last");
	}
}
  1. Run test and observe that multiple Transfer-Encoding with the value chunked are logged.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions