Marek Hawrylczak opened SPR-15914 and commented
Currently all requests except GET and HEAD are using transfer-encoding: chunked. There is no way to disable it, thus is not possible to call a network device that cannot support chunked transfer.
Affects: 5.0 RC3
Comment From: spring-projects-issues
Arjen Poutsma commented
The chunked transfer-encoding headers is coming from Reactor Netty, the underlying HTTP library. There is an open issue to add a global option for disabling it. Once there, the configuration option can easily be used via this ReactorClientHttpConnector constructor.
Comment From: spring-projects-issues
Alex commented
It seems like Reactor Netty has added the feature, but I don't still find the option in ReactorClientHttpConnector constructor now. Is there any plan to support it or am I missing something?
Comment From: spring-projects-issues
Arjen Poutsma commented
Alex It has been added in the 0.8.x branch, while Spring Framework is on 0.7. We will upgrade to 0.8.x as part of the 5.1 cycle.
In the mean time, I've asked for that feature to be back ported to 0.7, see my comment on the linked issue.
Comment From: spring-projects-issues
Simon commented
It would be really nice to be able to use WebClient for communicating with resources that dont support chunked encoding and to avoid adding additional 3rd party dependencies for just doing that.
Comment From: spring-projects-issues
Simon commented
It would also be nice to be able to configure it using the WebClient.Builder without the need to use the reactor.netty.http.client.HttpClient
Comment From: Tetradeus
Even when setting the Content-Length header at WebClient Level, this one is not passed to Netty at "configured" state, and Netty keeps chunking.
Comment From: vaibsgharge
Any update on this issue, please? I'm setting webclient.contentLength() explicitly still the response is getting chunked.
Comment From: rstoyanchev
I don't think there is anything to update. According to the Javadoc of HttpClient:
* {@code Transfer-Encoding: chunked} will be applied for those HTTP methods for which
* a request body is expected. {@code Content-Length} provided via request headers
* will disable {@code Transfer-Encoding: chunked}.
In other words, this is in Reactor Netty and unless WebClient is somehow not passing the header, I don't see how it could be related to it.
Comment From: jmini
I found an interesting pointer:
If it is of type
Mono
, then spring-reactor-netty will calculate the content length and send aFullHttpMessage
. If it is of typeFlux
, it will consider this as a chunked content and thus we will not calculate the content length.
source: https://stackoverflow.com/a/57891001
Comment From: yazinnnn
so, is there any way to disable chunked transfer or calculate encoded multipart/form-data part's content-length when using declare http interface ?
e.g.
@HttpExchange("/V1.0")
interface Client {
@PostExchange("upload")
fun postFile(
@RequestPart file: Resource,
//@RequestHeader("Content-Length") contentLength: Int
): Mono<String>
}
how can i set the correct content length header?