|
@@ -1,57 +0,0 @@
|
|
|
-package com.ywt.gateway.filter;
|
|
|
-
|
|
|
-
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
|
|
-import org.springframework.cloud.gateway.filter.GlobalFilter;
|
|
|
-import org.springframework.cloud.gateway.filter.factory.SetResponseHeaderGatewayFilterFactory;
|
|
|
-import org.springframework.core.Ordered;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-import org.springframework.web.server.ServerWebExchange;
|
|
|
-import reactor.core.publisher.Mono;
|
|
|
-
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-/**
|
|
|
- * 用于处理返回的Content-Type,与请求方保持一致
|
|
|
- */
|
|
|
-//@Component
|
|
|
-public class GlobalReponseHeaderFilter implements GlobalFilter, Ordered {
|
|
|
- private static final Logger log = LoggerFactory.getLogger(GlobalReponseHeaderFilter.class);
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private SetResponseHeaderGatewayFilterFactory factory;
|
|
|
-
|
|
|
- /**
|
|
|
- * 执行过滤器中的业务逻辑
|
|
|
- *
|
|
|
- * @param exchange
|
|
|
- * @param chain
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
|
|
- // 修改请求报文头
|
|
|
- SetResponseHeaderGatewayFilterFactory.NameValueConfig config = new SetResponseHeaderGatewayFilterFactory.NameValueConfig();
|
|
|
- List<String> strings = exchange.getRequest().getHeaders().get("Content-Type");
|
|
|
- String contentType = strings.get(0);
|
|
|
- config.setName("Content-Type");
|
|
|
- config.setValue(contentType);
|
|
|
- return factory.apply(config).filter(exchange, chain);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 指定过滤器的执行顺序,数值越小,过滤器的优先级越高,越先执行
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public int getOrder() {
|
|
|
- return Ordered.LOWEST_PRECEDENCE;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-}
|