cleaned up CORS filter implementation

pull/516/head
Justin Richer 11 years ago
parent 6ff4ae1458
commit 64bbb73d1b

@ -7,28 +7,29 @@ import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.GenericFilterBean;
import org.springframework.web.filter.OncePerRequestFilter;
/**
*
* Implements Cross-Origin Resource Sharing (CORS) headers. This filter adds the CORS
* headers to all requests that pass through it, and as such it should be used only
* on endpoints that require CORS support.
*
* @author jricher
*
*/
@Component("corsFilter")
public class CorsFilter extends GenericFilterBean {
public class CorsFilter extends OncePerRequestFilter {
/* (non-Javadoc)
* @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
*/
@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest)req;
HttpServletResponse response = (HttpServletResponse)resp;
public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException, ServletException {
response.addHeader("Access-Control-Allow-Origin", "*");
if (request.getHeader("Access-Control-Request-Method") != null && "OPTIONS".equals(request.getMethod())) {

Loading…
Cancel
Save