- 
                Notifications
    You must be signed in to change notification settings 
- Fork 38.8k
Closed
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: bugA general bugA general bug
Milestone
Description
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:
- Duplicate content-length header using Netty4ClientHttpRequestFactory [SPR-15476] #20036 Duplicate content-length header using Netty4ClientHttpRequestFactory ("is duplicated by")
- RestTemplate POST and PUT don't work with Netty4ClientHttpRequestFactory [SPR-14860] #19426 RestTemplate POST and PUT don't work with Netty4ClientHttpRequestFactory
Metadata
Metadata
Assignees
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: bugA general bugA general bug