package org.superdev.coddy;

import org.springframework.stereotype.Component;

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

@Component
public class CorsConfig implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
            throws IOException, ServletException {

        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;

        response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
        response.setHeader("Access-Control-Allow-Credentials", "true");
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.setHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With, remember-me");

        filterChain.doFilter(servletRequest, servletResponse);
    }

    @Override
    public void destroy() {

    }
}

@@ -22,16 +22,61 @@
 coddy;%0A%0A
+import org.springframework.http.HttpHeaders;%0A
 import o
@@ -779,37 +779,47 @@
 der(
-%22Access-Control-Allow-Origin%22
+HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN
 , re
@@ -877,110 +877,130 @@
 der(
-%22Access-Control-Allow-Credentials%22, %22true%22);%0A        response.setHeader(%22Access-Control-Allow-Methods%22
+HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, %22true%22);%0A        response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS
 , %22P
@@ -1055,32 +1055,42 @@
 der(
-%22Access-Control-Max-Age%22
+HttpHeaders.ACCESS_CONTROL_MAX_AGE
 , %223
@@ -1127,38 +1127,48 @@
 der(
-%22Access-Control-Allow-Headers%22
+HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS
 , %22C

use HttpHeaders constants