File tree Expand file tree Collapse file tree
gateway/src/main/java/com/github/cadecode/uniboot/gateway/filter Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .github .cadecode .uniboot .gateway .filter ;
2+
3+ import org .springframework .cloud .gateway .filter .GatewayFilterChain ;
4+ import org .springframework .cloud .gateway .filter .GlobalFilter ;
5+ import org .springframework .http .server .reactive .ServerHttpRequest ;
6+ import org .springframework .stereotype .Component ;
7+ import org .springframework .web .server .ServerWebExchange ;
8+ import reactor .core .publisher .Mono ;
9+
10+ /**
11+ * 请求头统一过滤
12+ *
13+ * @author Cade Li
14+ * @since 2023/8/8
15+ */
16+ @ Component
17+ public class RequestHeaderFilter implements GlobalFilter {
18+
19+ @ Override
20+ public Mono <Void > filter (ServerWebExchange exchange , GatewayFilterChain chain ) {
21+ // 去掉内部调用专用的请求头,防止伪造
22+ ServerHttpRequest request = exchange .getRequest ().mutate ()
23+ .headers (h -> {
24+ h .remove ("from-source" );
25+ h .remove ("inner-user-details" );
26+ })
27+ .build ();
28+ return chain .filter (exchange .mutate ().request (request ).build ());
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments