Re-enables MultipartEnvironmentPostProcessor
Closes gh-3527
This commit is contained in:
@@ -37,7 +37,7 @@ public class MultipartEnvironmentPostProcessor implements EnvironmentPostProcess
|
||||
// no user set property, set it to false.
|
||||
MapPropertySource propertySource = new MapPropertySource(MULTIPART_PROPERTY_SOURCE_NAME,
|
||||
Map.of(MULTIPART_ENABLED_PROPERTY, Boolean.FALSE));
|
||||
// environment.getPropertySources().addFirst(propertySource);
|
||||
environment.getPropertySources().addFirst(propertySource);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -488,7 +489,7 @@ public class ServerMvcIntegrationTests {
|
||||
@Test
|
||||
public void rewritePathPostLocalWorks() {
|
||||
restClient.post()
|
||||
.uri("/baz/post")
|
||||
.uri("/baz/localpost")
|
||||
.bodyValue("hello")
|
||||
.header("Host", "www.rewritepathpostlocal.org")
|
||||
.exchange()
|
||||
@@ -640,8 +641,21 @@ public class ServerMvcIntegrationTests {
|
||||
private void assertMultipartData(Map responseBody) {
|
||||
Map<String, Object> files = (Map<String, Object>) responseBody.get("files");
|
||||
assertThat(files).containsKey("imgpart");
|
||||
String file = (String) files.get("imgpart");
|
||||
assertThat(file).startsWith("data:").contains(";base64,");
|
||||
Object imgpart = files.get("imgpart");
|
||||
if (imgpart instanceof List l) {
|
||||
String file = (String) l.get(0);
|
||||
assertThat(isPNG(file.getBytes()));
|
||||
}
|
||||
else {
|
||||
String file = (String) imgpart;
|
||||
assertThat(file).startsWith("data:").contains(";base64,");
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isPNG(byte[] bytes) {
|
||||
byte[] pngSignature = { (byte) 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A };
|
||||
byte[] header = Arrays.copyOf(bytes, pngSignature.length);
|
||||
return Arrays.equals(pngSignature, header);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1288,8 +1302,7 @@ public class ServerMvcIntegrationTests {
|
||||
// @formatter:off
|
||||
return route("testform")
|
||||
.POST("/post", host("**.testform.org"), http())
|
||||
.before(new LocalServerPortUriResolver())
|
||||
.filter(prefixPath("/test"))
|
||||
.filter(new HttpbinUriResolver())
|
||||
.filter(addRequestHeader("X-Test", "form"))
|
||||
.build();
|
||||
// @formatter:on
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.gateway.server.mvc.common;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
@@ -28,7 +27,6 @@ import static org.springframework.cloud.gateway.server.mvc.common.MultipartEnvir
|
||||
public class MultipartEnvironmentPostProcessorTests {
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
void multipartDisabledByDefault() {
|
||||
MockEnvironment environment = new MockEnvironment();
|
||||
MultipartEnvironmentPostProcessor processor = new MultipartEnvironmentPostProcessor();
|
||||
|
||||
@@ -16,27 +16,21 @@
|
||||
|
||||
package org.springframework.cloud.gateway.server.mvc.test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
@RestController
|
||||
@@ -58,35 +52,7 @@ public class TestController {
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping(value = "/post", consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
|
||||
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public Map<String, Object> postFormData(HttpServletRequest request,
|
||||
@RequestParam MultiValueMap<String, MultipartFile> parts) throws ServletException, IOException {
|
||||
HashMap<String, Object> ret = new HashMap<>();
|
||||
ret.put("headers", getHeaders(request));
|
||||
HashMap<String, Object> files = new HashMap<>();
|
||||
ret.put("files", files);
|
||||
|
||||
parts.values().stream().flatMap(List::stream).forEach(part -> {
|
||||
String contentType = part.getContentType();
|
||||
long contentLength = part.getSize();
|
||||
// TODO: get part data
|
||||
files.put(part.getName(), "data:" + contentType + ";base64," + contentLength);
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
@PostMapping(path = "/post", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
|
||||
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public Map<String, Object> postUrlEncoded(HttpServletRequest request,
|
||||
@RequestBody(required = false) MultiValueMap form) throws IOException {
|
||||
HashMap<String, Object> ret = new HashMap<>();
|
||||
ret.put("headers", getHeaders(request));
|
||||
ret.put("form", form);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@PostMapping(path = "/post", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@PostMapping(path = "/localpost", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public Map<String, Object> post(HttpServletRequest request, @RequestBody(required = false) String body) {
|
||||
HashMap<String, Object> ret = new HashMap<>();
|
||||
ret.put("headers", getHeaders(request));
|
||||
|
||||
Reference in New Issue
Block a user