Merge branch '6.2.x'
This commit is contained in:
commit
764d35c072
|
@ -147,11 +147,11 @@ public class DefaultServerWebExchange implements ServerWebExchange {
|
||||||
ServerCodecConfigurer configurer, String logPrefix) {
|
ServerCodecConfigurer configurer, String logPrefix) {
|
||||||
|
|
||||||
MediaType contentType = getContentType(request);
|
MediaType contentType = getContentType(request);
|
||||||
if (contentType == null || !contentType.isCompatibleWith(MediaType.APPLICATION_FORM_URLENCODED)) {
|
if (contentType == null || !contentType.isConcrete() || !contentType.isCompatibleWith(MediaType.APPLICATION_FORM_URLENCODED)) {
|
||||||
return EMPTY_FORM_DATA;
|
return EMPTY_FORM_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpMessageReader<MultiValueMap<String, String>> reader = getReader(configurer, MediaType.APPLICATION_FORM_URLENCODED, FORM_DATA_TYPE);
|
HttpMessageReader<MultiValueMap<String, String>> reader = getReader(configurer, contentType, FORM_DATA_TYPE);
|
||||||
if (reader == null) {
|
if (reader == null) {
|
||||||
return Mono.error(new IllegalStateException("No HttpMessageReader for " + contentType));
|
return Mono.error(new IllegalStateException("No HttpMessageReader for " + contentType));
|
||||||
}
|
}
|
||||||
|
@ -165,7 +165,7 @@ public class DefaultServerWebExchange implements ServerWebExchange {
|
||||||
private Mono<MultiValueMap<String, Part>> initMultipartData(ServerCodecConfigurer configurer, String logPrefix) {
|
private Mono<MultiValueMap<String, Part>> initMultipartData(ServerCodecConfigurer configurer, String logPrefix) {
|
||||||
|
|
||||||
MediaType contentType = getContentType(this.request);
|
MediaType contentType = getContentType(this.request);
|
||||||
if (contentType == null || !contentType.getType().equalsIgnoreCase("multipart")) {
|
if (contentType == null || !contentType.isConcrete() || !contentType.getType().equalsIgnoreCase("multipart")) {
|
||||||
return EMPTY_MULTIPART_DATA;
|
return EMPTY_MULTIPART_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.codec.ServerCodecConfigurer;
|
import org.springframework.http.codec.ServerCodecConfigurer;
|
||||||
|
import org.springframework.http.codec.multipart.Part;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
import org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver;
|
import org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver;
|
||||||
|
@ -60,14 +61,25 @@ class DefaultServerWebExchangeTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // gh-34660
|
@Test // gh-34660
|
||||||
void useFormDataMessageReaderWhenAllContentType() {
|
void shouldNotDecodeFormDataWhenContentTypeNotConcrete() {
|
||||||
MockServerHttpRequest request = MockServerHttpRequest
|
MockServerHttpRequest request = MockServerHttpRequest
|
||||||
.post("https://example.com")
|
.post("https://example.com")
|
||||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.ALL_VALUE)
|
.header(HttpHeaders.CONTENT_TYPE, MediaType.ALL_VALUE)
|
||||||
.body("project=spring");
|
.body("project=spring");
|
||||||
ServerWebExchange exchange = createExchange(request);
|
ServerWebExchange exchange = createExchange(request);
|
||||||
MultiValueMap<String, String> body = exchange.getFormData().block();
|
MultiValueMap<String, String> body = exchange.getFormData().block();
|
||||||
assertThat(body.get("project")).contains("spring");
|
assertThat(body).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test // gh-34660
|
||||||
|
void shouldNotDecodeMultipartWhenContentTypeNotConcrete() {
|
||||||
|
MockServerHttpRequest request = MockServerHttpRequest
|
||||||
|
.post("https://example.com")
|
||||||
|
.header(HttpHeaders.CONTENT_TYPE, "multipart/*")
|
||||||
|
.body("project=spring");
|
||||||
|
ServerWebExchange exchange = createExchange(request);
|
||||||
|
MultiValueMap<String, Part> body = exchange.getMultipartData().block();
|
||||||
|
assertThat(body).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue