code: public static String generateHostHeader(URI uri) {
          String host = uri.getHost();
          if (isUsingNonDefaultPort(uri)) {
              host += ":" + uri.getPort();
          }
          return host;
      }
docs: Returns a host header according to the specified URI. The host header is generated with the same logic used by
  apache http client, that is, append the port to hostname only if it is not the default port.
  
  @param uri the URI
  @return a host header according to the specified URI.