Browse Source

Remove workaround for encoded parameters with mutate()

pull/222/head
Spencer Gibb 7 years ago
parent
commit
fb4a425f56
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 2
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/AddRequestParameterGatewayFilterFactory.java
  2. 5
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/GatewayFilterFactory.java
  3. 2
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/HystrixGatewayFilterFactory.java
  4. 2
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/PrefixPathGatewayFilterFactory.java
  5. 2
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/RewritePathGatewayFilterFactory.java
  6. 2
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/SetPathGatewayFilterFactory.java
  7. 1
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/GatewayServerHttpRequestBuilder.java
  8. 21
      spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/AddRequestHeaderGatewayFilterFactoryTests.java
  9. 43
      spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/AddRequestParameterGatewayFilterFactoryTests.java

2
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/AddRequestParameterGatewayFilterFactory.java

@ -70,7 +70,7 @@ public class AddRequestParameterGatewayFilterFactory implements GatewayFilterFac @@ -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) {

5
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/GatewayFilterFactory.java

@ -19,7 +19,6 @@ package org.springframework.cloud.gateway.filter.factory; @@ -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 { @@ -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();
}
}

2
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/HystrixGatewayFilterFactory.java

@ -158,7 +158,7 @@ public class HystrixGatewayFilterFactory implements GatewayFilterFactory { @@ -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));
}

2
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/PrefixPathGatewayFilterFactory.java

@ -55,7 +55,7 @@ public class PrefixPathGatewayFilterFactory implements GatewayFilterFactory { @@ -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();

2
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/RewritePathGatewayFilterFactory.java

@ -54,7 +54,7 @@ public class RewritePathGatewayFilterFactory implements GatewayFilterFactory { @@ -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();

2
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/SetPathGatewayFilterFactory.java

@ -73,7 +73,7 @@ public class SetPathGatewayFilterFactory implements GatewayFilterFactory { @@ -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();

1
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/support/GatewayServerHttpRequestBuilder.java

@ -29,6 +29,7 @@ import reactor.core.publisher.Flux; @@ -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;

21
spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/AddRequestHeaderGatewayFilterFactoryTests.java

@ -27,16 +27,12 @@ import org.springframework.context.annotation.Import; @@ -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 @@ -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

43
spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/factory/AddRequestParameterGatewayFilterFactoryTests.java

@ -38,10 +38,6 @@ import static org.assertj.core.api.Assertions.assertThat; @@ -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 @@ -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

Loading…
Cancel
Save