riptide icon indicating copy to clipboard operation
riptide copied to clipboard

Netty 4 Does Not Send Request Body

Open lukasniemeier-zalando opened this issue 6 years ago • 6 comments

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

lukasniemeier-zalando avatar Nov 16 '19 14:11 lukasniemeier-zalando

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.

lukasniemeier-zalando avatar Nov 16 '19 14:11 lukasniemeier-zalando

Might be related to https://github.com/spring-projects/spring-framework/issues/19426

whiskeysierra avatar Nov 21 '19 15:11 whiskeysierra

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

whiskeysierra avatar Nov 21 '19 15:11 whiskeysierra

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.

whiskeysierra avatar Nov 21 '19 15:11 whiskeysierra

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

lukasniemeier-zalando avatar Nov 21 '19 17:11 lukasniemeier-zalando

https://github.com/spring-projects/spring-framework/commit/ec8391a7fbc8ba67d1a04c9b93408230345fec36#diff-f6d905d4521bc40e2eadc060adb89078

whiskeysierra avatar Feb 11 '20 21:02 whiskeysierra