code: private static String getXForwardedHeader(StaplerRequest req, String header, String defaultValue) {
          String value = req.getHeader(header);
          if (value != null) {
              int index = value.indexOf(',');
              return index == -1 ? value.trim() : value.substring(0,index).trim();
          }
          return defaultValue;
      }
docs: Gets the originating "X-Forwarded-..." header from the request. If there are multiple headers the originating
  header is the first header. If the originating header contains a comma separated list, the originating entry
  is the first one.
  @param req the request
  @param header the header name
  @param defaultValue the value to return if the header is absent.
  @return the originating entry of the header or the default value if the header was not present.