Copy headers from part in MultipartBodyBuilder
This commit makes sure that Part.headers() is copied over when adding a part in the MultipartBodyBuilder. Closes gh-26410
This commit is contained in:
@@ -30,7 +30,6 @@ import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.codec.multipart.FilePart;
|
||||
import org.springframework.http.codec.multipart.Part;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -129,13 +128,14 @@ public final class MultipartBodyBuilder {
|
||||
Assert.notNull(part, "'part' must not be null");
|
||||
|
||||
if (part instanceof Part) {
|
||||
PartBuilder builder = asyncPart(name, ((Part) part).content(), DataBuffer.class);
|
||||
Part partObject = (Part) part;
|
||||
PartBuilder builder = asyncPart(name, partObject.content(), DataBuffer.class);
|
||||
if (!partObject.headers().isEmpty()) {
|
||||
builder.headers(headers -> headers.putAll(partObject.headers()));
|
||||
}
|
||||
if (contentType != null) {
|
||||
builder.contentType(contentType);
|
||||
}
|
||||
if (part instanceof FilePart) {
|
||||
builder.filename(((FilePart) part).filename());
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user