Commit c99cba83 by wangnb

订单服务跨域处理--think.wang

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@28365 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent 55653e8c
package com.glsx.gateway.config;
import com.glsx.plat.common.utils.StringUtils;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.gateway.discovery.DiscoveryClientRouteDefinitionLocator;
import org.springframework.cloud.gateway.discovery.DiscoveryLocatorProperties;
......@@ -14,7 +13,6 @@ import org.springframework.http.codec.ServerCodecConfigurer;
import org.springframework.http.codec.support.DefaultServerCodecConfigurer;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.util.CollectionUtils;
import org.springframework.web.cors.reactive.CorsUtils;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
......@@ -22,13 +20,12 @@ import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;
/**
*
* @author zhanghj
* @version 1.0.0
* @Title CorsConfig.java
* @Package com.glsx.gateway.config
* @Description 跨域配置
* @author zhanghj
* @date 2019年2月19日 上午11:43:35
* @version 1.0.0
*/
@Configuration
public class CorsConfig {
......@@ -45,23 +42,18 @@ public class CorsConfig {
HttpMethod requestMethod = requestHeaders
.getAccessControlRequestMethod();
HttpHeaders headers = response.getHeaders();
if(StringUtils.isEmpty(headers.getAccessControlAllowOrigin())){
headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN,
requestHeaders.getOrigin());
}
headers.addAll(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS,
requestHeaders.getAccessControlRequestHeaders());
if (requestMethod != null) {
headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS,
requestMethod.name());
}
if(CollectionUtils.isEmpty(headers.get(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS))){
headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS,"true");
}
headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS,
"true");
headers.add(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, "*");
if(headers.getAccessControlMaxAge() == -1){
headers.add(HttpHeaders.ACCESS_CONTROL_MAX_AGE, MAX_AGE);
}
if (request.getMethod() == HttpMethod.OPTIONS) {
response.setStatusCode(HttpStatus.OK);
return Mono.empty();
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!