Skip to content

Commit cfae40a

Browse files
committed
Return 415 for form data with @RequestBody in WebFlux
Closes gh-26386
1 parent 1b1ae33 commit cfae40a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageReaderArgumentResolver.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,6 +37,7 @@
3737
import org.springframework.core.io.buffer.DataBuffer;
3838
import org.springframework.core.io.buffer.DataBufferUtils;
3939
import org.springframework.http.HttpMethod;
40+
import org.springframework.http.HttpStatus;
4041
import org.springframework.http.MediaType;
4142
import org.springframework.http.codec.HttpMessageReader;
4243
import org.springframework.http.server.reactive.ServerHttpRequest;
@@ -49,6 +50,7 @@
4950
import org.springframework.web.bind.support.WebExchangeDataBinder;
5051
import org.springframework.web.reactive.BindingContext;
5152
import org.springframework.web.reactive.result.method.HandlerMethodArgumentResolverSupport;
53+
import org.springframework.web.server.ResponseStatusException;
5254
import org.springframework.web.server.ServerWebExchange;
5355
import org.springframework.web.server.ServerWebInputException;
5456
import org.springframework.web.server.UnsupportedMediaTypeStatusException;
@@ -155,8 +157,10 @@ protected Mono<Object> readBody(MethodParameter bodyParam, @Nullable MethodParam
155157
Object[] hints = extractValidationHints(bodyParam);
156158

157159
if (mediaType.isCompatibleWith(MediaType.APPLICATION_FORM_URLENCODED)) {
158-
return Mono.error(new IllegalStateException(
159-
"In a WebFlux application, form data is accessed via ServerWebExchange.getFormData()."));
160+
if (logger.isDebugEnabled()) {
161+
logger.debug("Form data is accessed via ServerWebExchange.getFormData() in WebFlux.");
162+
}
163+
return Mono.error(new ResponseStatusException(HttpStatus.UNSUPPORTED_MEDIA_TYPE));
160164
}
161165

162166
if (logger.isDebugEnabled()) {

0 commit comments

Comments
 (0)