Support multipart/mixed and related in DefaultServerWebExchange
See gh-29671
This commit is contained in:
committed by
rstoyanchev
parent
17bc3facaa
commit
67df0756cd
@@ -32,6 +32,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.codec.multipart.FilePart;
|
||||
import org.springframework.http.codec.multipart.FormFieldPart;
|
||||
import org.springframework.http.codec.multipart.Part;
|
||||
import org.springframework.http.converter.FormHttpMessageConverter;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
@@ -55,14 +56,38 @@ class MultipartHttpHandlerIntegrationTests extends AbstractHttpHandlerIntegratio
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
void getFormParts(HttpServer httpServer) throws Exception {
|
||||
void getFormPartsFormdata(HttpServer httpServer) throws Exception {
|
||||
performTest(httpServer, MediaType.MULTIPART_FORM_DATA);
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
void getFormPartsMixed(HttpServer httpServer) throws Exception {
|
||||
performTest(httpServer, MediaType.MULTIPART_MIXED);
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
void getFormPartsRelated(HttpServer httpServer) throws Exception {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
restTemplate.getMessageConverters().stream()
|
||||
.filter(FormHttpMessageConverter.class::isInstance)
|
||||
.map(FormHttpMessageConverter.class::cast)
|
||||
.findFirst()
|
||||
.orElseThrow()
|
||||
.addSupportedMediaTypes(MediaType.MULTIPART_RELATED);
|
||||
performTest(httpServer, MediaType.MULTIPART_RELATED, restTemplate);
|
||||
}
|
||||
|
||||
private void performTest(HttpServer httpServer, MediaType mediaType) throws Exception {
|
||||
performTest(httpServer, mediaType, new RestTemplate());
|
||||
}
|
||||
|
||||
private void performTest(HttpServer httpServer, MediaType mediaType, RestTemplate restTemplate) throws Exception {
|
||||
startServer(httpServer);
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
RequestEntity<MultiValueMap<String, Object>> request = RequestEntity
|
||||
.post(URI.create("http://localhost:" + port + "/form-parts"))
|
||||
.contentType(MediaType.MULTIPART_FORM_DATA)
|
||||
.contentType(mediaType)
|
||||
.body(generateBody());
|
||||
ResponseEntity<Void> response = restTemplate.exchange(request, Void.class);
|
||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
|
||||
Reference in New Issue
Block a user