Skip to content
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

RestTemplate with Netty produces two Content-Length headers [SPR-15241] #19806

spring-projects-issues opened this issue Feb 9, 2017 · 1 comment
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug


Copy link

spring-projects-issues commented Feb 9, 2017

Zeljko Tomic opened SPR-15241 and commented

RestTemplate with Netty4ClientHttpRequestFactory produces two Content-Length headers.

It can be easily reproduced with little modification of org/springframework/http/client/AbstractMockWebServerTestCase, just add one assertation (assertTrue("Multiple Content-Length request headers received", request.getHeaders().toMultimap().get("Content-Length").size() == 1);) and run RestTemplateIntegrationTests.

If needed, I can share sample project to reproduce issue with Spring Boot 1.5.1.RELEASE and AbstractMockWebServiceTestCase and RestTemplateIntegrationTests copied from spring-framework master branch.

private MockResponse postRequest(RecordedRequest request, String expectedRequestContent,
			String location, String contentType, byte[] responseBody) {
		assertTrue("Multiple Content-Length request headers received", request.getHeaders().toMultimap().get("Content-Length").size() == 1);
		assertTrue("Invalid request content-length",
				Integer.parseInt(request.getHeader("Content-Length")) > 0);
		String requestContentType = request.getHeader("Content-Type");
		assertNotNull("No content-type", requestContentType);
		Charset charset = StandardCharsets.ISO_8859_1;
		if (requestContentType.contains("charset=")) {
			String charsetName = requestContentType.split("charset=")[1];
			charset = Charset.forName(charsetName);
		assertEquals("Invalid request body", expectedRequestContent, request.getBody().readString(charset));
		Buffer buf = new Buffer();
		return new MockResponse()
				.setHeader("Location", baseUrl + location)
				.setHeader("Content-Type", contentType)
				.setHeader("Content-Length", responseBody.length)

Affects: 4.3.6

Issue Links:

Referenced from: commits 08b9e7b, 4ff1767

Copy link
Collaborator Author

spring-projects-issues commented Feb 13, 2017

Brian Clozel commented

Thanks for this report!
This should be fixed in the next 4.3.7.BUILD-SNAPSHOT and 5.0.0.BUILD-SNAPSHOT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
None yet

No branches or pull requests

2 participants