code: public static Header[] getHeadersFromRequest(HttpServletRequest request) {
          List<Header> returnHeaderList = new ArrayList<>();
          Enumeration<String> headerNames = request.getHeaderNames();
  
          while (headerNames.hasMoreElements()) {
              String headerName = headerNames.nextElement();
  
              Enumeration<String> headerValues = request.getHeaders(headerName);
              while (headerValues.hasMoreElements()) {
                  String headerValue = headerValues.nextElement();
                  // as cookies are sent in headers, we'll also have to check for unsupported cookies here
                  if (headerName.toLowerCase().equals("cookie")) {
                      String[] cookies = headerValue.split(";");
                      List<String> newCookieList = new ArrayList<>();
                      for (int i = 0; i < cookies.length; i++) {
                          final String cookieFromArray = cookies[i];
                          newCookieList.add(cookieFromArray);
                      }
                      // rewrite the cookie value
                      headerValue = StringUtils.join(newCookieList, ";");
                  }
  
                  if (headerValue.isEmpty()) {
                      LOG.debug("Skipping request header '" + headerName + "' as it's value is empty (possibly an "
                          + "unsupported cookie value has been removed)");
                  } else {
                      LOG.debug("Adding request header: " + headerName + "=" + headerValue);
                      returnHeaderList.add(new BasicHeader(headerName, headerValue));
                  }
              }
  
          }
  
          Header[] headersArray = new Header[returnHeaderList.size()];
          headersArray = returnHeaderList.toArray(headersArray);
          return headersArray;
      }
docs: Extract headers from {@link HttpServletRequest}
  
  @param request {@link HttpServletRequest} to extract headers from
  @return Array with {@link Header}s