我正在实施一个过滤器来设置
httpServletResponse.setHeader("X-XSS-Protection", "1; mode=block");
我已经写了过滤器。我想检查它是否工作完美。
我想从响应对象中读取标题。但我不知道该怎么做。
任何人都可以告诉如何做到这一点。
或者如果有更好的方法,请告诉我。
编辑
更新代码
public void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain filterChain)
throws IOException, ServletException
{
final HttpServletResponse response = (HttpServletResponse) res;
final HttpServletRequest request = (HttpServletRequest) req;
//set X-XSS-protection in http header, other http headers can be added in same way
String value = enable ? "1" : "0";
if(block)
{
value += "; mode=block";
}
PrintWriter out = response.getWriter();
out.println("ready to set xss");
response.setHeader("X-XSS-protection", value);
out.println("<br/><br/>Xss has been set");
filterChain.doFilter(req, res);
out.println("<br/><br/>XSS"+request.getHeader("X-XSS-protection"));
out.println("<br/><br/>job done");
}
我收到“XSSnull”
请帮助我如何纠正它。
提前致谢。