Merge branch '6.0.x'
This commit is contained in:
commit
ad5bf2fac8
|
|
@ -146,7 +146,15 @@ public interface ServerWebExchange {
|
||||||
* @since 6.0.10
|
* @since 6.0.10
|
||||||
* @see Part#delete()
|
* @see Part#delete()
|
||||||
*/
|
*/
|
||||||
Mono<Void> cleanupMultipart();
|
default Mono<Void> cleanupMultipart() {
|
||||||
|
return getMultipartData()
|
||||||
|
.onErrorResume(t -> Mono.empty()) // ignore errors reading multipart data
|
||||||
|
.flatMapIterable(Map::values)
|
||||||
|
.flatMapIterable(Function.identity())
|
||||||
|
.flatMap(part -> part.delete()
|
||||||
|
.onErrorResume(ex -> Mono.empty()))
|
||||||
|
.then();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the {@link LocaleContext} using the configured
|
* Return the {@link LocaleContext} using the configured
|
||||||
|
|
|
||||||
|
|
@ -324,30 +324,28 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder {
|
||||||
|
|
||||||
private final Mono<MultiValueMap<String, Part>> multipartDataMono;
|
private final Mono<MultiValueMap<String, Part>> multipartDataMono;
|
||||||
|
|
||||||
private volatile boolean multipartRead = false;
|
|
||||||
|
|
||||||
|
|
||||||
DelegatingServerWebExchange(ServerHttpRequest request, Map<String, Object> attributes,
|
DelegatingServerWebExchange(ServerHttpRequest request, Map<String, Object> attributes,
|
||||||
ServerWebExchange delegate, List<HttpMessageReader<?>> messageReaders) {
|
ServerWebExchange delegate, List<HttpMessageReader<?>> messageReaders) {
|
||||||
|
|
||||||
this.request = request;
|
this.request = request;
|
||||||
this.attributes = attributes;
|
this.attributes = attributes;
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
this.formDataMono = initFormData(messageReaders);
|
this.formDataMono = initFormData(request, messageReaders);
|
||||||
this.multipartDataMono = initMultipartData(request, messageReaders);
|
this.multipartDataMono = initMultipartData(request, messageReaders);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private Mono<MultiValueMap<String, String>> initFormData(List<HttpMessageReader<?>> readers) {
|
private static Mono<MultiValueMap<String, String>> initFormData(ServerHttpRequest request,
|
||||||
|
List<HttpMessageReader<?>> readers) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MediaType contentType = this.request.getHeaders().getContentType();
|
MediaType contentType = request.getHeaders().getContentType();
|
||||||
if (MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(contentType)) {
|
if (MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(contentType)) {
|
||||||
return ((HttpMessageReader<MultiValueMap<String, String>>) readers.stream()
|
return ((HttpMessageReader<MultiValueMap<String, String>>) readers.stream()
|
||||||
.filter(reader -> reader.canRead(FORM_DATA_TYPE, MediaType.APPLICATION_FORM_URLENCODED))
|
.filter(reader -> reader.canRead(FORM_DATA_TYPE, MediaType.APPLICATION_FORM_URLENCODED))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElseThrow(() -> new IllegalStateException("No form data HttpMessageReader.")))
|
.orElseThrow(() -> new IllegalStateException("No form data HttpMessageReader.")))
|
||||||
.readMono(FORM_DATA_TYPE, this.request, Hints.none())
|
.readMono(FORM_DATA_TYPE, request, Hints.none())
|
||||||
.doOnNext(ignored -> this.multipartRead = true)
|
|
||||||
.switchIfEmpty(EMPTY_FORM_DATA)
|
.switchIfEmpty(EMPTY_FORM_DATA)
|
||||||
.cache();
|
.cache();
|
||||||
}
|
}
|
||||||
|
|
@ -400,23 +398,7 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder {
|
||||||
return this.multipartDataMono;
|
return this.multipartDataMono;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// Delegating methods
|
||||||
public Mono<Void> cleanupMultipart() {
|
|
||||||
if (this.multipartRead) {
|
|
||||||
return getMultipartData()
|
|
||||||
.onErrorResume(t -> Mono.empty()) // ignore errors reading multipart data
|
|
||||||
.flatMapIterable(Map::values)
|
|
||||||
.flatMapIterable(Function.identity())
|
|
||||||
.flatMap(part -> part.delete()
|
|
||||||
.onErrorResume(ex -> Mono.empty()))
|
|
||||||
.then();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return Mono.empty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delegating methods
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServerHttpResponse getResponse() {
|
public ServerHttpResponse getResponse() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue