Raod 3 years ago
parent 0f08c7e8c7
commit 23741e36a2

@ -3,10 +3,10 @@ package com.anjiplus.template.gaea.business.filter;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.server.reactive.ServerHttpRequest;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@ -21,19 +21,17 @@ public class CORSFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
ServerHttpRequest req = (ServerHttpRequest) request;
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
// 设置允许Cookie
res.addHeader("Access-Control-Allow-Credentials", "true");
// 允许http://www.xxx.com域自行设置这里只做示例发起跨域请求
res.addHeader("Access-Control-Allow-Origin", req.getHeaders().getOrigin());
res.addHeader("Access-Control-Allow-Origin", req.getHeader("Origin"));
// 设置允许跨域请求的方法
res.addHeader("Access-Control-Allow-Methods", "*");
// 允许跨域请求包含content-type
res.addHeader("Access-Control-Allow-Headers", "*");
// if (((HttpServletRequest) request).getMethod().equals("OPTIONS")) {
// response.getWriter().println("ok");
// }
res.addHeader("Access-Control-Expose-Headers", "*");
chain.doFilter(request, response);
}

Loading…
Cancel
Save