Support empty body without content type in WebFlux
Issue: SPR-15758
This commit is contained in:
@@ -83,14 +83,16 @@ public class MessageReaderArgumentResolverTests {
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void missingContentType() throws Exception {
|
||||
ServerWebExchange exchange = post("/path").body("{\"bar\":\"BARBAR\",\"foo\":\"FOOFOO\"}").toExchange();
|
||||
ResolvableType type = forClassWithGenerics(Mono.class, TestBean.class);
|
||||
MethodParameter param = this.testMethod.arg(type);
|
||||
Mono<Object> result = this.resolver.readBody(param, true, this.bindingContext, exchange);
|
||||
Mono<TestBean> value = (Mono<TestBean>) result.block(Duration.ofSeconds(1));
|
||||
|
||||
StepVerifier.create(result).expectError(UnsupportedMediaTypeStatusException.class).verify();
|
||||
StepVerifier.create(value).expectError(UnsupportedMediaTypeStatusException.class).verify();
|
||||
}
|
||||
|
||||
// More extensive "empty body" tests in RequestBody- and HttpEntityArgumentResolverTests
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.web.reactive.result.method.annotation;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import io.reactivex.Maybe;
|
||||
@@ -106,6 +107,14 @@ public class RequestBodyArgumentResolverTests {
|
||||
assertNull(body);
|
||||
}
|
||||
|
||||
@Test // SPR-15758
|
||||
public void emptyBodyWithoutContentType() throws Exception {
|
||||
MethodParameter param = this.testMethod.annot(requestBody().notRequired()).arg(Map.class);
|
||||
String body = resolveValueWithEmptyBody(param);
|
||||
|
||||
assertNull(body);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void emptyBodyWithMono() throws Exception {
|
||||
@@ -262,6 +271,7 @@ public class RequestBodyArgumentResolverTests {
|
||||
@RequestBody(required = false) Observable<String> obsNotRequired,
|
||||
@RequestBody(required = false) io.reactivex.Observable<String> rxjava2ObsNotRequired,
|
||||
@RequestBody(required = false) CompletableFuture<String> futureNotRequired,
|
||||
@RequestBody(required = false) Map<?, ?> mapNotRequired,
|
||||
String notAnnotated) {}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user