webflux 使用异步非阻塞的方式,传递Header还需要我们自己增加代码传递:
定义过滤器,便携下面的配置可以尝试一下header的传递到后面的服务中。
@Component public class AuthorizationFilter implements WebFilter { @Override public Monofilter(ServerWebExchange exchange, WebFilterChain chain) { ServerHttpRequest mutatedRequest = exchange.getRequest().mutate().header(HttpHeaders.AUTHORIZATION, "Bearer " + authHeader).build(); ServerWebExchange mutatedExchange = exchange.mutate().request(mutatedRequest).build(); return chain.filter(mutatedExchange); } } ## Kotlin 的方式 @Component class AuthorizationFilter : WebFilter { override fun filter(exchange: ServerWebExchange, chain: WebFilterChain): Mono { val mutatedRequest = exchange.request.mutate().header(HttpHeaders.AUTHORIZATION, "Bearer $authHeader").build() val mutatedExchange = exchange.mutate().request(mutatedRequest).build() return chain.filter(mutatedExchange) } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)