|
@@ -77,6 +77,7 @@ import org.springframework.web.server.ServerWebExchange;
|
|
|
import org.springframework.web.server.WebFilter;
|
|
|
import org.springframework.web.server.WebFilterChain;
|
|
|
import reactor.core.publisher.Mono;
|
|
|
+import static com.boman.common.core.utils.obj.ObjectUtils.*;
|
|
|
|
|
|
/** 跨域请求
|
|
|
* @author shiqian
|
|
@@ -92,10 +93,27 @@ public class CrosConfig {
|
|
|
if (CorsUtils.isCorsRequest(request)) {
|
|
|
ServerHttpResponse response = ctx.getResponse();
|
|
|
HttpHeaders headers = response.getHeaders();
|
|
|
- headers.add("Access-Control-Allow-Origin", "*");
|
|
|
+
|
|
|
+ if(isEmpty(headers.get("Access-Control-Allow-Credentials"))) {
|
|
|
+ // 设置允许Cookie
|
|
|
+ headers.add("Access-Control-Allow-Credentials", "true");
|
|
|
+ }
|
|
|
+ if(isEmpty(headers.get("Access-Control-Allow-Origin"))) {
|
|
|
+ // 允许http://www.xxx.com域(自行设置,这里只做示例)发起跨域请求
|
|
|
+ headers.add("Access-Control-Allow-Origin", "*");
|
|
|
+ }
|
|
|
+ if(isEmpty(headers.get("Access-Control-Allow-Methods"))) {
|
|
|
+ // 设置允许跨域请求的方法
|
|
|
+ headers.add("Access-Control-Allow-Methods", "*");
|
|
|
+ }
|
|
|
+ if(isEmpty(headers.get("Access-Control-Allow-Headers"))) {
|
|
|
+ // 设置允许跨域请求的方法
|
|
|
+ headers.add("Access-Control-Allow-Headers", "*");
|
|
|
+ }
|
|
|
+/* headers.add("Access-Control-Allow-Origin", "*");
|
|
|
headers.add("Access-Control-Allow-Methods", "*");
|
|
|
headers.add("Access-Control-Allow-Headers", "*");
|
|
|
- headers.add("Access-Control-Allow-Credentials", "true");
|
|
|
+ headers.add("Access-Control-Allow-Credentials", "true");*/
|
|
|
if (request.getMethod() == HttpMethod.OPTIONS) {
|
|
|
response.setStatusCode(HttpStatus.OK);
|
|
|
return Mono.empty();
|