This is a question related to Capture and log the response body. What if I only want to log the response headers, and not the entire body? Is there a different approach than described in the linked question?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’d like to override the
HttpServletResponse#addHeader()andHttpServletResponse#setHeader()method instead.There are indeed more methods which sets the headers, but in a bit decent servletcontainer implementation they all delegate to this one method (I’ve verified it in both Tomcat and Glassfish).
Alternatively, you can also make use of servletcontainer specific logging capabilities. Tomcat for example seems to support logging of response headers by a valve.