gateway 过滤器
Posted draymond
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了gateway 过滤器相关的知识,希望对你有一定的参考价值。
@Component @Configuration public class GateWayFilter implements GlobalFilter, Ordered { @Override public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) { ServerHttpRequest request = exchange.getRequest(); ServerHttpResponse response = exchange.getResponse(); System.out.println("request: " + JSONUtil.toJsonStr(request)); //-------- uri ---------- URI uri = request.getURI(); System.out.println("uri: " + JSONUtil.toJsonStr(uri)); String path = uri.getPath(); String scheme = uri.getScheme(); int port = uri.getPort(); String authority = uri.getAuthority(); String query = uri.getQuery(); String host = uri.getHost(); String schemeSpecificPart = uri.getSchemeSpecificPart(); // ----------- body ------------ Flux<DataBuffer> body = request.getBody(); // ----------- query ------------ System.out.println(); MultiValueMap<String, String> queryParams = request.getQueryParams(); Set<String> keys = queryParams.keySet(); for (String key : keys) { System.out.print(" key:" + key + " value:" + queryParams.getFirst(key)); } System.out.println(); HttpHeaders headers = request.getHeaders(); //uri: {"path":"/payment/get/1","scheme":"http","port":9527,"authority":"localhost:9527","query":"realName=draymond&password=123456","host":"localhost","schemeSpecificPart":"//localhost:9527/payment/get/1?realName=draymond&password=123456"} return chain.filter(exchange); }
请求参数 url信息
body信息
head信息
以上是关于gateway 过滤器的主要内容,如果未能解决你的问题,请参考以下文章
#yyds干货盘点# springcloud整合gateway实现网关全局过滤器功能
springcloud-Finchley学习笔记-gateway网关自定义过滤器
SpringCloud06_Gateway的概述工程案例代码微服务动态路由Predicate的使用详解Filter(建议收藏)
SpringCloud 统一网关Gateway -- 全局过滤器 GlobalFilter@Order注解过滤器链执行顺序Gateway跨域问题处理