diff --git a/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java b/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java index 75051383..35f06a62 100644 --- a/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java +++ b/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java @@ -67,7 +67,7 @@ public class GatewayAutoConfiguration { public HttpClient httpClient() { return HttpClient.create(opts -> { //opts.poolResources(PoolResources.elastic("proxy")); - //opts.disablePool(); + opts.disablePool(); //TODO: why do I need this again? }); } diff --git a/src/test/java/org/springframework/cloud/gateway/test/GatewayIntegrationTests.java b/src/test/java/org/springframework/cloud/gateway/test/GatewayIntegrationTests.java index 72d2ac9c..dcf42809 100644 --- a/src/test/java/org/springframework/cloud/gateway/test/GatewayIntegrationTests.java +++ b/src/test/java/org/springframework/cloud/gateway/test/GatewayIntegrationTests.java @@ -1,5 +1,6 @@ package org.springframework.cloud.gateway.test; +import java.nio.charset.Charset; import java.time.Duration; import java.util.Map; @@ -18,12 +19,18 @@ import org.springframework.cloud.gateway.filter.route.SecureHeadersProperties; import org.springframework.cloud.gateway.handler.RoutePredicateHandlerMapping; import org.springframework.context.annotation.Bean; import org.springframework.core.annotation.Order; +import org.springframework.core.io.ClassPathResource; +import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.RestTemplate; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.ClientResponse; import org.springframework.web.reactive.function.client.WebClient; @@ -64,11 +71,12 @@ public class GatewayIntegrationTests { private int port = 0; private WebClient webClient; + private String baseUri; @Before public void setup() { //TODO: how to set new ReactorClientHttpConnector() - String baseUri = "http://localhost:" + port; + baseUri = "http://localhost:" + port; this.webClient = WebClient.create(baseUri); } @@ -256,9 +264,10 @@ public class GatewayIntegrationTests { formData.add("foo", "bar"); formData.add("baz", "bam"); + MediaType contentType = new MediaType(MediaType.APPLICATION_FORM_URLENCODED, Charset.forName("UTF-8")); Mono result = webClient.post() .uri("/post") - .contentType(MediaType.APPLICATION_FORM_URLENCODED) + .contentType(contentType) .exchange(BodyInserters.fromFormData(formData)) .then(response -> response.body(toMono(Map.class))); @@ -272,6 +281,27 @@ public class GatewayIntegrationTests { .verify(DURATION); } + @Test + public void multipartFormDataWorks() { + MultiValueMap form = new LinkedMultiValueMap<>(); + form.add("file", new ClassPathResource("1x1.png")); + + RestTemplate restTemplate = new RestTemplate(); + + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.MULTIPART_FORM_DATA); + + HttpEntity> entity = new HttpEntity<>(form, headers); + + ResponseEntity response = restTemplate.exchange(baseUri + "/post", HttpMethod.POST, entity, Map.class); + + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + Map files = getMap(response.getBody(), "files"); + assertThat(files).containsKey("file"); + assertThat((String)files.get("file")).startsWith("data:application/octet-stream;base64,"); + System.out.println(); + } + @Test public void postWorks() { Mono result = webClient.post() diff --git a/src/test/resources/1x1.png b/src/test/resources/1x1.png new file mode 100644 index 00000000..134aa5b7 Binary files /dev/null and b/src/test/resources/1x1.png differ