Remove workaround for encoded parameters with mutate()
This commit is contained in:
@@ -70,7 +70,7 @@ public class AddRequestParameterGatewayFilterFactory implements GatewayFilterFac
|
||||
.build(true)
|
||||
.toUri();
|
||||
|
||||
ServerHttpRequest request = mutate(exchange.getRequest()).uri(newUri).build();
|
||||
ServerHttpRequest request = exchange.getRequest().mutate().uri(newUri).build();
|
||||
|
||||
return chain.filter(exchange.mutate().request(request).build());
|
||||
} catch (RuntimeException ex) {
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.cloud.gateway.filter.factory;
|
||||
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilter;
|
||||
import org.springframework.cloud.gateway.support.ArgumentHints;
|
||||
import org.springframework.cloud.gateway.support.GatewayServerHttpRequestBuilder;
|
||||
import org.springframework.cloud.gateway.support.NameUtils;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.tuple.Tuple;
|
||||
@@ -39,8 +38,8 @@ public interface GatewayFilterFactory extends ArgumentHints {
|
||||
return NameUtils.normalizeFilterName(getClass());
|
||||
}
|
||||
|
||||
|
||||
@Deprecated
|
||||
default ServerHttpRequest.Builder mutate(ServerHttpRequest request) {
|
||||
return new GatewayServerHttpRequestBuilder(request);
|
||||
return request.mutate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ public class HystrixGatewayFilterFactory implements GatewayFilterFactory {
|
||||
.toUri();
|
||||
exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, requestUrl);
|
||||
|
||||
ServerHttpRequest request = mutate(this.exchange.getRequest()).uri(requestUrl).build();
|
||||
ServerHttpRequest request = this.exchange.getRequest().mutate().uri(requestUrl).build();
|
||||
ServerWebExchange mutated = exchange.mutate().request(request).build();
|
||||
return RxReactiveStreams.toObservable(HystrixGatewayFilterFactory.this.dispatcherHandler.handle(mutated));
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class PrefixPathGatewayFilterFactory implements GatewayFilterFactory {
|
||||
addOriginalRequestUrl(exchange, req.getURI());
|
||||
String newPath = prefix + req.getURI().getPath();
|
||||
|
||||
ServerHttpRequest request = mutate(req)
|
||||
ServerHttpRequest request = req.mutate()
|
||||
.path(newPath)
|
||||
.build();
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ public class RewritePathGatewayFilterFactory implements GatewayFilterFactory {
|
||||
String path = req.getURI().getPath();
|
||||
String newPath = path.replaceAll(regex, replacement);
|
||||
|
||||
ServerHttpRequest request = mutate(req)
|
||||
ServerHttpRequest request = req.mutate()
|
||||
.path(newPath)
|
||||
.build();
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ public class SetPathGatewayFilterFactory implements GatewayFilterFactory {
|
||||
|
||||
exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, uri);
|
||||
|
||||
ServerHttpRequest request = mutate(req)
|
||||
ServerHttpRequest request = req.mutate()
|
||||
.path(newPath)
|
||||
.build();
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import reactor.core.publisher.Flux;
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
@Deprecated
|
||||
public class GatewayServerHttpRequestBuilder implements ServerHttpRequest.Builder {
|
||||
|
||||
private boolean encoded;
|
||||
|
||||
@@ -27,16 +27,12 @@ import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
import static org.springframework.cloud.gateway.test.TestUtils.getMap;
|
||||
import static org.springframework.web.reactive.function.BodyExtractors.toMono;
|
||||
|
||||
|
||||
/**
|
||||
@@ -51,20 +47,15 @@ public class AddRequestHeaderGatewayFilterFactoryTests extends BaseWebClientTest
|
||||
|
||||
@Test
|
||||
public void addRequestHeaderFilterWorks() {
|
||||
Mono<Map> result = webClient.get()
|
||||
testClient.get()
|
||||
.uri("/headers")
|
||||
.header("Host", "www.addrequestheader.org")
|
||||
.exchange()
|
||||
.flatMap(response -> response.body(toMono(Map.class)));
|
||||
|
||||
StepVerifier.create(result)
|
||||
.consumeNextWith(
|
||||
response -> {
|
||||
Map<String, Object> headers = getMap(response, "headers");
|
||||
assertThat(headers).containsEntry("X-Request-Foo", "Bar");
|
||||
})
|
||||
.expectComplete()
|
||||
.verify(Duration.ofMinutes(10));
|
||||
.expectBody(Map.class)
|
||||
.consumeWith(result -> {
|
||||
Map<String, Object> headers = getMap(result.getResponseBody(), "headers");
|
||||
assertThat(headers).containsEntry("X-Request-Foo", "Bar");
|
||||
});
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
|
||||
@@ -38,10 +38,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.containsEncodedQuery;
|
||||
import static org.springframework.cloud.gateway.test.TestUtils.getMap;
|
||||
import static org.springframework.web.reactive.function.BodyExtractors.toMono;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = RANDOM_PORT)
|
||||
@@ -73,31 +69,26 @@ public class AddRequestParameterGatewayFilterFactoryTests extends BaseWebClientT
|
||||
}
|
||||
URI uri = UriComponentsBuilder.fromUriString(this.baseUri+"/get" + query).build(true).toUri();
|
||||
boolean checkForEncodedValue = containsEncodedQuery(uri);
|
||||
Mono<Map> result = webClient.get()
|
||||
testClient.get()
|
||||
.uri(uri)
|
||||
.header("Host", "www.addrequestparameter.org")
|
||||
.exchange()
|
||||
.flatMap(response -> response.body(toMono(Map.class)));
|
||||
|
||||
StepVerifier.create(result)
|
||||
.consumeNextWith(
|
||||
response -> {
|
||||
Map<String, Object> args = getMap(response, "args");
|
||||
assertThat(args).containsEntry("foo", "bar");
|
||||
if (name != null) {
|
||||
if (checkForEncodedValue) {
|
||||
try {
|
||||
assertThat(args).containsEntry(name, URLDecoder.decode(value, "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
assertThat(args).containsEntry(name, value);
|
||||
}
|
||||
}
|
||||
})
|
||||
.expectComplete()
|
||||
.verify(DURATION);
|
||||
.expectBody(Map.class)
|
||||
.consumeWith(response -> {
|
||||
Map<String, Object> args = getMap(response.getResponseBody(), "args");
|
||||
assertThat(args).containsEntry("foo", "bar");
|
||||
if (name != null) {
|
||||
if (checkForEncodedValue) {
|
||||
try {
|
||||
assertThat(args).containsEntry(name, URLDecoder.decode(value, "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
assertThat(args).containsEntry(name, value);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
|
||||
Reference in New Issue
Block a user