package com.ycl.config; import javax.servlet.*; import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** * @author lyq * @version 1.0 * @date 2022/09/06 16:52 */ public class WebSecurityCorsFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse res = (HttpServletResponse) response; res.setHeader("Access-Control-Allow-Origin", "*"); res.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT"); res.setHeader("Access-Control-Max-Age", "3600"); res.setHeader("Access-Control-Allow-Headers", "Authorization, Content-Type, Accept, x-requested-with, Cache-Control, os, version, source"); chain.doFilter(request, res); } @Override public void destroy() { } }