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

Closed
spring-issuemaster opened this issue Feb 9, 2017 · 1 comment

Comments

@spring-issuemaster
Copy link
Collaborator

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();
		buf.write(responseBody);
		return new MockResponse()
				.setHeader("Location", baseUrl + location)
				.setHeader("Content-Type", contentType)
				.setHeader("Content-Length", responseBody.length)
				.setBody(buf)
				.setResponseCode(201);
}

Affects: 4.3.6

Issue Links:

  • #20036 Duplicate content-length header using Netty4ClientHttpRequestFactory ("is duplicated by")
  • #19426 RestTemplate POST and PUT don't work with Netty4ClientHttpRequestFactory

Referenced from: commits 08b9e7b, 4ff1767

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

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
Projects
None yet
2 participants
You can’t perform that action at this time.