Adds PrefixPathRouteFilter

This commit is contained in:
Spencer Gibb
2017-03-10 12:02:25 -07:00
parent 0faee92e0a
commit 67162a9775
4 changed files with 54 additions and 21 deletions

View File

@@ -143,6 +143,9 @@ TODO: document AddResponseHeader Route Filter
=== Hystrix Route Filter
TODO: document Hystrix Route Filter
=== PrefixPath Route Filter
TODO: document PrefixPath Route Filter
=== RedirectTo Route Filter
TODO: document RedirectTo Route Filter

View File

@@ -27,6 +27,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.gateway.actuate.GatewayEndpoint;
import org.springframework.cloud.gateway.filter.route.PrefixPathRouteFilter;
import org.springframework.cloud.gateway.model.RouteLocator;
import org.springframework.cloud.gateway.model.RouteWriter;
import org.springframework.cloud.gateway.filter.GlobalFilter;
@@ -236,6 +237,11 @@ public class GatewayAutoConfiguration {
}
}
@Bean(name = "PrefixPathRouteFilter")
public PrefixPathRouteFilter prefixPathRouteFilter() {
return new PrefixPathRouteFilter();
}
@Bean(name = "RedirectToRouteFilter")
public RedirectToRouteFilter redirectToRouteFilter() {
return new RedirectToRouteFilter();

View File

@@ -0,0 +1,45 @@
/*
* Copyright 2013-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.springframework.cloud.gateway.filter.route;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.server.WebFilter;
/**
* @author Spencer Gibb
*/
public class PrefixPathRouteFilter implements RouteFilter {
@Override
@SuppressWarnings("unchecked")
public WebFilter apply(String... args) {
validate(1, args);
final String prefix = args[0];
return (exchange, chain) -> {
ServerHttpRequest req = exchange.getRequest();
String newPath = prefix + req.getURI().getPath();
ServerHttpRequest request = req.mutate()
.path(newPath)
.build();
return chain.filter(exchange.mutate().request(request).build());
};
}
}

View File

@@ -159,27 +159,6 @@ public class BaseWebClientTests {
});
}
@Bean(name="PrefixPathRouteFilter")
public RouteFilter prefixPathRouteFilter() {
return new RouteFilter() {
@Override
public WebFilter apply(String... args) {
validate(1, args);
final String prefix = args[0];
return (exchange, chain) -> {
ServerHttpRequest req = exchange.getRequest();
String newPath = prefix + req.getURI().getPath();
ServerHttpRequest request = req.mutate()
.path(newPath)
.build();
return chain.filter(exchange.mutate().request(request).build());
};
}
};
}
@Bean
@Order(500)
public GlobalFilter modifyResponseFilter() {