Skip to content

Commit

Permalink
Removes custom form url handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
spencergibb committed Dec 13, 2017
1 parent 5afa1c8 commit 1b3300b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,16 @@
package org.springframework.cloud.gateway.filter;

import java.net.URI;
import java.util.List;
import java.util.Map;

import org.springframework.core.Ordered;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.web.server.ServerWebExchange;

import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.CLIENT_RESPONSE_ATTR;
import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.GATEWAY_REQUEST_URL_ATTR;
import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.isAlreadyRouted;
import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.setAlreadyRouted;
import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.*;

import io.netty.buffer.Unpooled;
import io.netty.handler.codec.http.DefaultHttpHeaders;
Expand Down Expand Up @@ -82,18 +76,6 @@ public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
.failOnClientError(false)
.headers(httpHeaders);

if (MediaType.APPLICATION_FORM_URLENCODED.includes(request.getHeaders().getContentType())) {
return exchange.getFormData()
.flatMap(map -> proxyRequest.sendForm(form -> {
for (Map.Entry<String, List<String>> entry: map.entrySet()) {
for (String value : entry.getValue()) {
form.attr(entry.getKey(), value);
}
}
}).then())
.then(chain.filter(exchange));
}

return proxyRequest.sendHeaders() //I shouldn't need this
.send(request.getBody()
.map(DataBuffer::asByteBuffer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.nio.charset.Charset;
import java.util.Map;

import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.SpringBootConfiguration;
Expand Down Expand Up @@ -51,29 +50,27 @@
@SuppressWarnings("unchecked")
public class FormIntegrationTests extends BaseWebClientTests {

public static final MediaType CONTENT_TYPE = new MediaType(MediaType.APPLICATION_FORM_URLENCODED, Charset.forName("UTF-8"));

@Test
@Ignore //FIXME: boot 2.0.x compatibility
public void formUrlencodedWorks() {
LinkedMultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
formData.add("foo", "bar");
formData.add("baz", "bam");

MediaType contentType = new MediaType(MediaType.APPLICATION_FORM_URLENCODED, Charset.forName("UTF-8"));
Mono<Map> result = webClient.post()
testClient.post()
.uri("/post")
.contentType(contentType)
.contentType(CONTENT_TYPE)
.body(BodyInserters.fromFormData(formData))
.exchange()
.flatMap(response -> response.body(toMono(Map.class)));

StepVerifier.create(result)
.consumeNextWith(map -> {
.expectStatus().isOk()
.expectBody(Map.class)
.consumeWith(result -> {
Map map = result.getResponseBody();
Map<String, Object> form = getMap(map, "form");
assertThat(form).containsEntry("foo", "bar");
assertThat(form).containsEntry("baz", "bam");
})
.expectComplete()
.verify(DURATION);
});
}

@Test
Expand Down

0 comments on commit 1b3300b

Please sign in to comment.