Skip to content

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

Closed

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

Activity

  1. spring-projects-issues commented on Feb 13, 2017

    @spring-projects-issues
    CollaboratorAuthor

    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.

  2. added
    type: bug
    in: web
    on Jan 11, 2019
  3. added this to the 4.3.7 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webtype: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions