@Test void addAllowOriginForCORSRequests() throws Exception { when(request.getMethod()).thenReturn("GET"); when(request.getHeader("Origin")).thenReturn("http: filter.doFilter(request, response, chain); verify(response).addHeader("Access-Control-Allow-Origin", "http: verify(chain).doFilter(request, response); }
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest)servletRequest; HttpServletResponse response = (HttpServletResponse)servletResponse; String origin = request.getHeader("Origin"); if (origin != null) { response.addHeader("Access-Control-Allow-Origin", origin); response.addHeader("Access-Control-Allow-Headers", "Origin, Content-Type, Accept"); response.setHeader("Access-Control-Max-Age", "1728000"); if (request.getMethod().equals("OPTIONS")) return; } chain.doFilter(request, response); }
CORSFilter implements Filter { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest)servletRequest; HttpServletResponse response = (HttpServletResponse)servletResponse; String origin = request.getHeader("Origin"); if (origin != null) { response.addHeader("Access-Control-Allow-Origin", origin); response.addHeader("Access-Control-Allow-Headers", "Origin, Content-Type, Accept"); response.setHeader("Access-Control-Max-Age", "1728000"); if (request.getMethod().equals("OPTIONS")) return; } chain.doFilter(request, response); } }
CORSFilter implements Filter { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest)servletRequest; HttpServletResponse response = (HttpServletResponse)servletResponse; String origin = request.getHeader("Origin"); if (origin != null) { response.addHeader("Access-Control-Allow-Origin", origin); response.addHeader("Access-Control-Allow-Headers", "Origin, Content-Type, Accept"); response.setHeader("Access-Control-Max-Age", "1728000"); if (request.getMethod().equals("OPTIONS")) return; } chain.doFilter(request, response); }  }
CORSFilter implements Filter { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest)servletRequest; HttpServletResponse response = (HttpServletResponse)servletResponse; String origin = request.getHeader("Origin"); if (origin != null) { response.addHeader("Access-Control-Allow-Origin", origin); response.addHeader("Access-Control-Allow-Headers", "Origin, Content-Type, Accept"); response.setHeader("Access-Control-Max-Age", "1728000"); if (request.getMethod().equals("OPTIONS")) return; } chain.doFilter(request, response); }  @Override void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain); @Override void destroy(); @Override void init(FilterConfig filterConfig); }
CORSFilter implements Filter { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest)servletRequest; HttpServletResponse response = (HttpServletResponse)servletResponse; String origin = request.getHeader("Origin"); if (origin != null) { response.addHeader("Access-Control-Allow-Origin", origin); response.addHeader("Access-Control-Allow-Headers", "Origin, Content-Type, Accept"); response.setHeader("Access-Control-Max-Age", "1728000"); if (request.getMethod().equals("OPTIONS")) return; } chain.doFilter(request, response); }  @Override void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain); @Override void destroy(); @Override void init(FilterConfig filterConfig);  }