Skip to content

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

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Referenced from: commits 08b9e7b, 4ff1767

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions