code: public static void appendSchemeHostPort(StringBuilder url, String scheme, String server, int port) {
          url.append(scheme).append("://").append(HostPort.normalizeHost(server));
  
          if (port > 0) {
              switch (scheme) {
                  case "http":
                      if (port != 80)
                          url.append(':').append(port);
                      break;
  
                  case "https":
                      if (port != 443)
                          url.append(':').append(port);
                      break;
  
                  default:
                      url.append(':').append(port);
              }
          }
      }
docs: Append scheme, host and port URI prefix, handling IPv6 address encoding and default ports
  
  @param url    StringBuilder to append to
  @param scheme the URI scheme
  @param server the URI server
  @param port   the URI port