version: spring-core-6.0.2

some times, server require multipart/form-data content sent with content-length, but boundary generated by PartHttpMessageWriter was using MimeTypeUtils, and which length is random! when i use curl, it load file and generate content-length automatic, but when i switch to reactor-netty-http, i could not figure auto the content length. And when content-length not set, framework add transfer-encoding header automaticlly!

when i send this request to some server, the server response 412!

Comment From: poutsma

If I understand correctly, you received a 412 Precondition Failed error, and think this is due to a missing Content-Length headers, which you assume is not there because of MimeTypeUtils::generateMultipartBoundary generating a random-length byte array.

Are you sure that the 412 is there because of a missing Content-Length header? Typically, this code is returned when a condition defined by the If-Unmodified-Since or If-None-Match headers is not fulfilled. A 411 code would indicate a missing Content-Length header.

At any rate, the reason we can not set the Content-Length in the PartHttpMessageWriter is not because of the random boundary length, but because when the request headers are written, the content (length) of the parts in the stream is not known yet. Instead, the content is created when the part is written, reactively.

So even if MimeTypeUtils::generateMultipartBoundary returned a fixed length array, there would still be no Content-Length header on multipart requests.