WebFlux multpart support polish + minor refactoring
This commit is contained in:
@@ -39,8 +39,6 @@ import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import static org.springframework.http.codec.multipart.MultipartHttpMessageReader.*;
|
||||
|
||||
/**
|
||||
* Implementations of {@link BodyExtractor} that read various bodies, such a reactive streams.
|
||||
*
|
||||
@@ -53,6 +51,9 @@ public abstract class BodyExtractors {
|
||||
private static final ResolvableType FORM_TYPE =
|
||||
ResolvableType.forClassWithGenerics(MultiValueMap.class, String.class, String.class);
|
||||
|
||||
private static final ResolvableType MULTIPART_TYPE = ResolvableType.forClassWithGenerics(
|
||||
MultiValueMap.class, String.class, Part.class);
|
||||
|
||||
|
||||
/**
|
||||
* Return a {@code BodyExtractor} that reads into a Reactor {@link Mono}.
|
||||
@@ -151,8 +152,8 @@ public abstract class BodyExtractors {
|
||||
HttpMessageReader<MultiValueMap<String, Part>> messageReader =
|
||||
multipartMessageReader(context);
|
||||
return context.serverResponse()
|
||||
.map(serverResponse -> messageReader.readMono(MULTIPART_VALUE_TYPE, MULTIPART_VALUE_TYPE, serverRequest, serverResponse, context.hints()))
|
||||
.orElseGet(() -> messageReader.readMono(MULTIPART_VALUE_TYPE, serverRequest, context.hints()));
|
||||
.map(serverResponse -> messageReader.readMono(MULTIPART_TYPE, MULTIPART_TYPE, serverRequest, serverResponse, context.hints()))
|
||||
.orElseGet(() -> messageReader.readMono(MULTIPART_TYPE, serverRequest, context.hints()));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -204,7 +205,7 @@ public abstract class BodyExtractors {
|
||||
private static HttpMessageReader<MultiValueMap<String, Part>> multipartMessageReader(BodyExtractor.Context context) {
|
||||
return context.messageReaders().get()
|
||||
.filter(messageReader -> messageReader
|
||||
.canRead(MULTIPART_VALUE_TYPE, MediaType.MULTIPART_FORM_DATA))
|
||||
.canRead(MULTIPART_TYPE, MediaType.MULTIPART_FORM_DATA))
|
||||
.findFirst()
|
||||
.map(BodyExtractors::<MultiValueMap<String, Part>>cast)
|
||||
.orElseThrow(() -> new IllegalStateException(
|
||||
|
||||
@@ -33,15 +33,12 @@ import org.springframework.http.ReactiveHttpOutputMessage;
|
||||
import org.springframework.http.client.reactive.ClientHttpRequest;
|
||||
import org.springframework.http.codec.HttpMessageWriter;
|
||||
import org.springframework.http.codec.ServerSentEvent;
|
||||
import org.springframework.http.codec.multipart.MultipartHttpMessageReader;
|
||||
import org.springframework.http.codec.multipart.Part;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import static org.springframework.http.codec.multipart.MultipartHttpMessageReader.*;
|
||||
|
||||
/**
|
||||
* Implementations of {@link BodyInserter} that write various bodies, such a reactive streams,
|
||||
* server-sent events, resources, etc.
|
||||
@@ -60,6 +57,9 @@ public abstract class BodyInserters {
|
||||
private static final ResolvableType FORM_TYPE =
|
||||
ResolvableType.forClassWithGenerics(MultiValueMap.class, String.class, String.class);
|
||||
|
||||
private static final ResolvableType MULTIPART_VALUE_TYPE = ResolvableType.forClassWithGenerics(
|
||||
MultiValueMap.class, String.class, Part.class);
|
||||
|
||||
private static final BodyInserter<Void, ReactiveHttpOutputMessage> EMPTY =
|
||||
(response, context) -> response.setComplete();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user