public static String getHeaders ( HttpServletResponse response ) { String headerString = "" ; Collection < String > headerNames = response . getHeaderNames ( ) ; for ( String headerName : headerNames ) { // there may be multiple headers per header name for ( String headerValue : response . getHeaders ( headerName ) ) { if ( headerString . length ( ) != 0 ) { headerString += "\n" ; } headerString += headerName + ": " + headerValue ; } } return headerString ; }
Obtain newline - delimited headers from response