Push canWrite down into MultipartHttpMessageWriter

The implementation in the base class only matches the
MultipartHttpMessageWriter subclass. The other two override it anyway.

Closes gh-29631
This commit is contained in:
rstoyanchev
2022-12-05 15:22:37 +00:00
parent a7bf14b364
commit 93ea2e1df9
3 changed files with 15 additions and 17 deletions

View File

@@ -145,6 +145,20 @@ public class MultipartHttpMessageWriter extends MultipartWriterSupport
}
@Override
public boolean canWrite(ResolvableType elementType, @Nullable MediaType mediaType) {
if (MultiValueMap.class.isAssignableFrom(elementType.toClass())) {
if (mediaType == null) {
return true;
}
for (MediaType supportedMediaType : getWritableMediaTypes()) {
if (supportedMediaType.isCompatibleWith(mediaType)) {
return true;
}
}
}
return false;
}
@Override
public Mono<Void> write(Publisher<? extends MultiValueMap<String, ?>> inputStream,

View File

@@ -24,7 +24,6 @@ import java.util.Map;
import reactor.core.publisher.Mono;
import org.springframework.core.ResolvableType;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.http.HttpHeaders;
@@ -34,7 +33,6 @@ import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.FastByteArrayOutputStream;
import org.springframework.util.MimeTypeUtils;
import org.springframework.util.MultiValueMap;
/**
* Support class for multipart HTTP message writers.
@@ -83,21 +81,6 @@ public class MultipartWriterSupport extends LoggingCodecSupport {
return this.supportedMediaTypes;
}
public boolean canWrite(ResolvableType elementType, @Nullable MediaType mediaType) {
if (MultiValueMap.class.isAssignableFrom(elementType.toClass())) {
if (mediaType == null) {
return true;
}
for (MediaType supportedMediaType : this.supportedMediaTypes) {
if (supportedMediaType.isCompatibleWith(mediaType)) {
return true;
}
}
}
return false;
}
/**
* Generate a multipart boundary.
* <p>By default delegates to {@link MimeTypeUtils#generateMultipartBoundary()}.