How to fix Findbugs HTTP parameter directly written to HTTP header output

后端 未结 2 962
-上瘾入骨i
-上瘾入骨i 2021-01-05 21:47

I have a class RequestFilter and @Override methods doFilterInternal. And when i add Header for response, findbugs show error HTTP parameter directly written to HTTP header o

相关标签:
2条回答
  • 2021-01-05 22:30

    I think this is HRS_REQUEST_PARAMETER_TO_HTTP_HEADER error, and you can fix it like that:

    String rqHd = request.getHeader("Access-Control-Request-Headers"); 
    if(rqHd != null){
        String rqHeader = URLEncoder.encode(rqHd,StandardCharsets.UTF_8.displayName());   
        response.addHeader("Access-Control-Allow-Headers", rqHeader);
    }
    
    0 讨论(0)
  • 2021-01-05 22:32

    Watch out if you wan't to set ETag header. ETag looks like W/"myetagvalue"

    String etagHd = request.getHeader(HttpHeaders.ETAG);    
    response.addHeader(HttpHeaders.ETAG,  URLEncoder.encode(etagHd,StandardCharsets.UTF_8.displayName()); 
    

    Will be encoded W%2F%22myetagvalue%22 be carefull !

    0 讨论(0)
提交回复
热议问题