Created
October 22, 2015 09:20
-
-
Save ekirastogi/6c818cb4bacb41012f26 to your computer and use it in GitHub Desktop.
CORS filter to allow cross domain ajax calls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ekiras.filter; | |
import org.springframework.stereotype.Component; | |
import javax.servlet.*; | |
import javax.servlet.http.HttpServletResponse; | |
import java.io.IOException; | |
/** | |
* Created by ekansh on 22/10/15. | |
*/ | |
@Component | |
public class CorsFilter implements Filter { | |
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { | |
HttpServletResponse response = (HttpServletResponse) res; | |
response.setHeader("Access-Control-Allow-Origin", "*"); | |
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); | |
response.setHeader("Access-Control-Max-Age", "3600"); | |
response.setHeader("Access-Control-Allow-Headers", "Content-Type, x-requested-with, X-Custom-Header"); | |
chain.doFilter(req, res); | |
} | |
public void init(FilterConfig filterConfig) {} | |
public void destroy() {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment