我有一个春季靴子样本,其中使用一个过滤器检查自定义标头的存在。示例代码如下:
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
logger.info("insert into AuthFilter.doFilter");
String token = request.getHeader("mid-goods-token");
logger.info("request..");
// check tokenÊÇ·ñΪ¿Õ
if (StringUtils.isEmpty(token)) {
Enumeration<String> headIndexes = request.getHeaderNames();
while(headIndexes.hasMoreElements()) {
String header = headIndexes.nextElement();
Enumeration<String> values = request.getHeader(header);
log.error("Msg: {} =>{}", header, values);
}
return;
}
}
然后我开始卷曲:
curl -H“中间商品令牌:abcdef59e3b764839b912f6358558d5c;” .... http://127.0.0.1/
我得到一个令人惊讶的结果,因为token
为空,而在迭代结果中确实看到了mid-goods-token
标头
2019-08-07/21:46:58.048|172.17.42.1|172.17.42.1-49-20190807214658-038467|1|^_^|[http-nio-11301-exec-1] INFO com.xxx.mid.web.config.filter.AuthFilter 62 - insert into AuthFilter.doFilter
2019-08-07/21:46:58.048|172.17.42.1|172.17.42.1-49-20190807214658-038467|1|^_^|[http-nio-11301-exec-1] INFO com.xxx.mid.web.config.filter.AuthFilter 65 - request.getHeader null, token: null
2019-08-07/21:46:58.048|172.17.42.1|172.17.42.1-49-20190807214658-038467|1|^_^|[http-nio-11301-exec-1] ERROR com.xxx.mid.web.config.filter.AuthFilter 73 - Msg: user-agent =>org.apache.tomcat.util.http.ValuesEnumerator@29625965
2019-08-07/21:46:58.049|172.17.42.1|172.17.42.1-49-20190807214658-038467|1|^_^|[http-nio-11301-exec-1] ERROR com.xxx.mid.web.config.filter.AuthFilter 73 - Msg: via =>org.apache.tomcat.util.http.ValuesEnumerator@7cdf0235
2019-08-07/21:46:58.049|172.17.42.1|172.17.42.1-49-20190807214658-038467|1|^_^|[http-nio-11301-exec-1] ERROR com.xxx.mid.web.config.filter.AuthFilter 73 - Msg: l5d-dst-service =>org.apache.tomcat.util.http.ValuesEnumerator@3ff990c7
2019-08-07/21:46:58.049|172.17.42.1|172.17.42.1-49-20190807214658-038467|1|^_^|[http-nio-11301-exec-1] ERROR com.xxx.mid.web.config.filter.AuthFilter 73 - Msg: accept =>org.apache.tomcat.util.http.ValuesEnumerator@707687a9
2019-08-07/21:46:58.049|172.17.42.1|172.17.42.1-49-20190807214658-038467|1|^_^|[http-nio-11301-exec-1] ERROR com.xxx.mid.web.config.filter.AuthFilter 73 - Msg: x-real-ip =>org.apache.tomcat.util.http.ValuesEnumerator@4b6451b3
2019-08-07/21:46:58.049|172.17.42.1|172.17.42.1-49-20190807214658-038467|1|^_^|[http-nio-11301-exec-1] ERROR com.xxx.mid.web.config.filter.AuthFilter 73 - Msg: l5d-dst-client =>org.apache.tomcat.util.http.ValuesEnumerator@4fae2c40
2019-08-07/21:46:58.049|172.17.42.1|172.17.42.1-49-20190807214658-038467|1|^_^|[http-nio-11301-exec-1] ERROR com.xxx.mid.web.config.filter.AuthFilter 73 - Msg: l5d-ctx-trace =>org.apache.tomcat.util.http.ValuesEnumerator@3ca2e2da
2019-08-07/21:46:58.050|172.17.42.1|172.17.42.1-49-20190807214658-038467|1|^_^|[http-nio-11301-exec-1] ERROR com.xxx.mid.web.config.filter.AuthFilter 73 - Msg: l5d-vk-host =>org.apache.tomcat.util.http.ValuesEnumerator@782d7128
2019-08-07/21:46:58.050|172.17.42.1|172.17.42.1-49-20190807214658-038467|1|^_^|[http-nio-11301-exec-1] ERROR com.xxx.mid.web.config.filter.AuthFilter 73 - Msg: mid-goods-token =>org.apache.tomcat.util.http.ValuesEnumerator@112d5e57
2019-08-07/21:46:58.050|172.17.42.1|172.17.42.1-49-20190807214658-038467|1|^_^|[http-nio-11301-exec-1] ERROR com.xxx.mid.web.config.filter.AuthFilter 73 - Msg: host =>org.apache.tomcat.util.http.ValuesEnumerator@2f5fac1e
2019-08-07/21:46:58.050|172.17.42.1|172.17.42.1-49-20190807214658-038467|1|^_^|[http-nio-11301-exec-1] ERROR com.xxx.mid.web.config.filter.AuthFilter 73 - Msg: l5d-reqid =>org.apache.tomcat.util.http.ValuesEnumerator@4402f1d
2019-08-07/21:46:58.050|172.17.42.1|172.17.42.1-49-20190807214658-038467|1|^_^|[http-nio-11301-exec-1] ERROR com.xxx.mid.web.config.filter.AuthFilter 73 - Msg: content-length =>org.apache.tomcat.util.http.ValuesEnumerator@17f7aa8c
2019-08-07/21:46:58.051|172.17.42.1|172.17.42.1-49-20190807214658-038467|1|^_^|[http-nio-11301-exec-1] ERROR com.xxx.mid.web.config.filter.AuthFilter 73 - Msg: l5d-ctx-dtab =>org.apache.tomcat.util.http.ValuesEnumerator@6cd381c3
2019-08-07/21:46:58.051|172.17.42.1|172.17.42.1-49-20190807214658-038467|1|^_^|[http-nio-11301-exec-1] ERROR com.xxx.mid.web.config.filter.AuthFilter 73 - Msg: x-forwarded-for =>org.apache.tomcat.util.http.ValuesEnumerator@3e3eef1b
使用getHeader()有什么问题吗?