随手记
public Mono<Void> notPass(ServerHttpResponse serverHttpResponse) {
serverHttpResponse.setStatusCode(HttpStatus.UNAUTHORIZED);
serverHttpResponse.getHeaders().add("Content-Type", "application/json;charset=UTF-8");
String resString = "{\"code\":\"-1\", \"msg\":\"不通过Gateway\"}";
DataBuffer buffer = serverHttpResponse.bufferFactory().wrap(resString.getBytes(StandardCharsets.UTF_8));
return serverHttpResponse.writeWith(Flux.just(buffer));
}
// 添加头文件
ServerHttpRequest.Builder builder = request.mutate();
builder.header("xxx", "xxx");
return chain.filter(exchange.mutate().request(builder.build()).build());