SpringCloudGateway
全局过滤器需要实现 org.springframework.cloud.gateway.filter.GlobalFilter
接口。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| @Component public class AuthFilter implements GlobalFilter, Ordered { @Override public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) { ServerHttpRequest request = exchange.getRequest(); ServerHttpRequest.Builder mutate = request.mutate(); String contentType = request.getHeaders().getFirst(HttpHeaders.CONTENT_TYPE); mutate.header(HttpHeaders.CONTENT_TYPE, URLEncoder.encode(MediaType.APPLICATION_JSON_VALUE, Constants.UTF8)); mutate.headers(httpHeaders -> httpHeaders.remove(name)).build(); return chain.filter(exchange.mutate().request(mutate.build()).build()); }
@Override public int getOrder() { return -200; } }
|
本文地址: https://github.com/maxzhao-it/blog/post/5fd3d0d2/