code: 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;
      }
docs: Obtain newline-delimited headers from response
  
  @param response HttpServletResponse to scan
  @return newline-delimited headers