标签:class requested etc options return tco wrap except token
@Component
public class CorsFilter implements Filter {
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException,
ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT, GET");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "x-requested-with");
response.setHeader("Access-Control-Allow-Headers", "token,userId,Content-Type,x-is-mini-program-environment");
response.setHeader("Access-Control-Allow-Credentials", "true");
// HttpServletRequestWrapper requestWrapper = new HttpServletRequestWrapper((HttpServletRequest) request) {
// /**
// */
// @Override
// public String getContentType() {
// // 先从原本的Request中获取头,如果为空且名字为token,则从参数中查找并返回
// String contentType = super.getContentType();
//
//// if("Content-Type".equals(name)){
//// String contentType = request.getHeader("Content-Type");
// return contentType.replace("multipart/form-data,","");
//// }
//// return superHeader;
// }
// };
// request.getContentType(); //setAttribute("Content-Type", contentType.replace("multipart/form-data,",""));
chain.doFilter(request, res);
}
@Override
public void init(FilterConfig filterConfig) {
}
@Override
public void destroy() {
}
}
标签:class requested etc options return tco wrap except token
原文地址:https://www.cnblogs.com/-mzh/p/11583598.html