응답 헤더 경량화

main
이범준 8 months ago
parent 5487bb9a02
commit 6c2b8e99ae

@ -0,0 +1,50 @@
package cokr.xit.base;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
@Component
@Order(-10001)
public class ResponseHeaderFilter implements Filter {
public ResponseHeaderFilter() {}
@Override
public void destroy() {}
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
chain.doFilter(request, new HttpServletResponseWrapper((HttpServletResponse) response) {
@Override
public void setHeader(String name, String value) {
if(name.equalsIgnoreCase("X-Xss-Protection")) {
if(super.containsHeader("Content-Type")) {
if(super.getContentType() != null) {
if(super.getContentType().startsWith("application/json")) {
return;
}
}
}
}
super.setHeader(name, value);
return;
}
});
}
}
Loading…
Cancel
Save