Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
matthew-js-porter opened this issue Dec 17, 2024 · 1 comment
Assignees
Milestone

Comments

@matthew-js-porter
Copy link

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.
@matthew-js-porter
Copy link
Author

@olegz Thank you for addressing this so quickly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants