package com.danchu.momuck.interceptor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by geine on 2017. 3. 13..
 */
@Component
public class CrosInterceptor implements Filter {

    private static final Logger LOG = LoggerFactory.getLogger(CrosInterceptor.class);

    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse) res;

        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.setHeader("Access-Control-Allow-Headers", "x-requested-with");
        response.setHeader("Access-Control-Allow-Origin", "*");
        chain.doFilter(req, res);
    }

    public void init(FilterConfig filterConfig) {
    }

    public void destroy() {
    }
}

@@ -143,31 +143,137 @@
 nt;%0A
-%0Aimport javax.servlet.*
+import org.springframework.web.filter.OncePerRequestFilter;%0A%0Aimport javax.servlet.*;%0Aimport javax.servlet.http.HttpServletRequest
 ;%0Aim
@@ -435,19 +435,30 @@
 tor 
-implement
+extend
 s 
+OncePerRequest
 Filt
@@ -550,30 +550,48 @@
 lass);%0A%0A    
-public
+@Override%0A%0A    protected
  void doFilt
@@ -592,17 +592,29 @@
 doFilter
-(
+Internal(Http
 ServletR
@@ -623,18 +623,26 @@
 uest req
-, 
+uest, Http
 ServletR
@@ -652,16 +652,21 @@
 onse res
+ponse
 , Filter
@@ -675,22 +675,40 @@
 ain 
-chain)
+filterChain)%0A           
  throws 
 IOEx
@@ -703,18 +703,23 @@
  throws 
-IO
+Servlet
 Exceptio
@@ -721,23 +721,18 @@
 eption, 
-Servlet
+IO
 Exceptio
@@ -747,157 +747,225 @@
     
-HttpServletResponse response = (HttpServletResponse) res;%0A%0A        response.setHeader(%22Access-Control-Allow-Methods%22, %22POST, GET, OPTIONS, DELETE%22);%0A
+response.addHeader(%22Access-Control-Allow-Origin%22, %22*%22);%0A%0A        if (request.getHeader(%22Access-Control-Request-Method%22) != null && %22OPTIONS%22.equals(request.getMethod())) %7B%0A            // CORS %22pre-flight%22 request%0A    
     
@@ -969,35 +969,35 @@
        response.
-set
+add
 Header(%22Access-C
@@ -1007,27 +1007,55 @@
 rol-
-Max-Age%22, %223600%22);%0A
+Allow-Methods%22, %22GET, POST, PUT, DELETE%22);%0A    
     
@@ -1059,35 +1059,35 @@
        response.
-set
+add
 Header(%22Access-C
@@ -1114,11 +1114,11 @@
 %22, %22
-x-r
+X-R
 eque
@@ -1126,205 +1126,102 @@
 ted-
-with%22);%0A        response.setHeader(%22Access-Control-Allow-Origin%22, %22*%22);%0A        chain.doFilter(req, res);
+With,Origin,Content-Type, Accept%22);%0A        %7D
 %0A    
-%7D%0A%0A
     
-public void init(FilterConfig filterConfig) %7B%0A    %7D%0A%0A    public void destroy() %7B
+filterChain.doFilter(request, response);
 %0A   

Fix filter