응답 헤더 경량화
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…
Reference in New Issue