package @app.group.id@.@app.name@.security;

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

// Prevents caching of REST service responses.
public class CachingPreventionFilter implements Filter {
    public void init(FilterConfig filterConfig) throws ServletException {
        // do nothing
    }

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        response.addIntHeader("Age", 0);
        response.addHeader("Cache-Control", "no-cache,no-store,no-transform,must-revalidate");
        response.addHeader("Expires", "Wed, 31 Dec 1969 23:59:59 GMT");
        response.addHeader("Pragma", "no-cache");
        response.addHeader("X-Robots-Tag", "noindex, nofollow");

        if (filterChain != null) {
            filterChain.doFilter(servletRequest, servletResponse);
        }
    }

    public void destroy() {
        // do nothing
    }
}
