Netty 4 Does Not Send Request Body
When using Netty4ClientHttpRequestFactory request bodies are not send to the server.
Expected Behavior
Request body is transmitted.
Actual Behavior
Server observes empty request body.
Steps to Reproduce
See https://github.com/zalando/riptide/commit/a85ce45b88f9385a37f348a37ece37af45d73ac3.
Your Environment
- Version used: https://github.com/zalando/riptide/commit/797dc47da604ab5346eff5e4bf3b699bb29a8e6f
Curiously request bodies are send/flushed when calling close on the body stream, like it's proposed for the request compression plugin in https://github.com/zalando/riptide/blob/f2dde3c28a5a080471a125f3eca7b6d4693ae28f/riptide-compression/src/main/java/org/zalando/riptide/compression/RequestCompressionPlugin.java#L68-L71.
Might be related to https://github.com/spring-projects/spring-framework/issues/19426
If I enable the factory in the request compression test it fails in mysterious ways:
Spring 4.x
- :heavy_check_mark:
shouldCompressWithGivenAlgorithm - :heavy_check_mark:
shouldCompressRequestBody - :x:
shouldBackOffIfAlreadyEncoded - :heavy_check_mark:
shouldNotCompressEmptyRequestBody
Spring 5.x
- :x:
shouldCompressWithGivenAlgorithm - :x:
shouldCompressRequestBody - :heavy_check_mark:
shouldBackOffIfAlreadyEncoded - :heavy_check_mark:
shouldNotCompressEmptyRequestBody
The following was added in between 4.x and 5.x within the Netty4ClientHttpRequest and fixes the issue in Spring 4.x:
if (!nettyRequest.headers().contains(HttpHeaders.CONTENT_LENGTH) && this.body.buffer().readableBytes() > 0) {
nettyRequest.headers().set(HttpHeaders.CONTENT_LENGTH, this.body.buffer().readableBytes());
}
Since that seems to be an issue in Spring I'd say it's not our task to fix. The issues in 5.x could be related to our compression and headers though. My idea was that we set the wrong content length and somehow the whole request is not send. But I can't prove that using the debugger.
The following was added in between 4.x and 5.x within the Netty4ClientHttpRequest and fixes the issue in Spring 4.x
Which is funny, see https://github.com/zalando/riptide/pull/822#discussion_r346240552
https://github.com/spring-projects/spring-framework/commit/ec8391a7fbc8ba67d1a04c9b93408230345fec36#diff-f6d905d4521bc40e2eadc060adb89078