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
180540
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);
            }
        }
    }
166093
public static base_response add(nitro_service client, server resource) throws Exception {
		server addresource = new server();
		addresource.name = resource.name;
		addresource.ipaddress = resource.ipaddress;
		addresource.domain = resource.domain;
		addresource.translationip = resource.translationip;
		addresource.translationmask = resource.translationmask;
		addresource.domainresolveretry = resource.domainresolveretry;
		addresource.state = resource.state;
		addresource.ipv6address = resource.ipv6address;
		addresource.comment = resource.comment;
		addresource.td = resource.td;
		return addresource.add_resource(client);
	}
833257
public static String formatAddress(InetSocketAddress inet){
        if(inet == null){
            throw new NullPointerException();
        }
        StringBuilder result = new StringBuilder();
        if(inet.isUnresolved()){
            result.append(inet.getHostName());
        }else{
            result.append(formatPossibleIpv6Address(formatAddress(inet.getAddress())));
        }
        result.append(":").append(inet.getPort());
        return result.toString();
    }
839504
public static URL toURL(String strUrl, int port, boolean encodeIfNecessary) throws MalformedURLException {
	URL url;
	try {
	    url = new URL(strUrl);
	}
	catch (MalformedURLException mue) {
	    url = new URL("http://" + strUrl);
	}
	if (!encodeIfNecessary) return url;
	return encodeURL(url, port);
    }
316298
public static URL buildPostUrl(String host, int port, String path) throws MalformedURLException {
        return buildPostUrl("http", host, port, path);
    }
436482
def ssl_domain_port_path(uri)
      uri = URI.parse(uri)
      ssl = uri.scheme == 'https'
      [ssl, uri.host, uri.port, uri.path]
    end
574371
protected void appendBaseURL(StringBuilder buffer,String resource,HTTPClientConfiguration configuration)
    {
        buffer.append("http");
        if(configuration.isSSL())
        {
            buffer.append("s");
        }
        buffer.append("://");
        buffer.append(configuration.getHostName());
        int port=configuration.getPort();
        if(port>0)
        {
            buffer.append(":");
            buffer.append(port);
        }
        if((resource!=null)&&(resource.length()>0))
        {
            if(!resource.startsWith("/"))
            {
                buffer.append("/");
            }
            buffer.append(resource);
        }
    }
1265342
private static String formatIPv6Addr(String host) {
        if (host == null) {
            return null;
        } else {
            return (new StringBuilder()).append("[").append(host).append("]").toString();
        }
    }
101103
public SdkClientBuilder defaultProxy(String hostname, int port, final String scheme)
    {
        this.defaultProxy = new HttpHost(hostname, port, scheme);
        return this;
    }
8689
function(url) {
		var ports = { // we ignore default ports
			http: 80,
			https: 443
		}
		, urlp = parseUrl(url)
		;

		return urlp.scheme + '://' + urlp.host + (urlp.port !== ports[urlp.scheme] ? ':' + urlp.port : '') + urlp.path + (urlp.query ? urlp.query : '');
	}
11772
public static void setJVMProxy(String host, String port) {
		System.setProperty(JVM_PROXY_HOST_PROPERTY, host);
		System.setProperty(JVM_PROXY_PORT_PROPERTY, port);
	}
1217342
public UrlBuilder withHost(String host) {
        if (host == null || host.isEmpty()) {
            this.host = null;
        } else {
            with(host, UrlTokenizerState.SCHEME_OR_HOST);
        }
        return this;
    }
889158
public static Map<String,String> httpMessagingConfiguration( String ip, int port ) {

		final Map<String,String> result = new LinkedHashMap<>();
		result.put( MessagingConstants.MESSAGING_TYPE_PROPERTY, HttpConstants.FACTORY_HTTP );
		result.put( HttpConstants.HTTP_SERVER_IP, ip == null ? HttpConstants.DEFAULT_IP : ip );
		result.put( HttpConstants.HTTP_SERVER_PORT, "" + (port <= 0 ? HttpConstants.DEFAULT_PORT : port));

		return result;
	}
1044875
def build(template='/', host=None, scheme=None, port=None, **template_vars):
        
        # TODO: refactor to build_absolute and build_relative instead of handling based on params
        parsed_host = urlparse.urlparse(host if host is not None else '')
        host_has_scheme = bool(parsed_host.scheme)

        if host_has_scheme:
            host = parsed_host.netloc
            # Prioritize scheme parameter, but if not specified, use scheme implied from host
            scheme = parsed_host.scheme if scheme is None else scheme

        port = port or parsed_host.port  # Default to port override

        unparsed_path = urlparse.urlparse(template.format(**template_vars)).geturl()

        # If a host was specified, try to return a full url
        if host:
            if not scheme:
                raise ValueError('No scheme supplied and scheme could not be inferred from the host: {}'.format(host))
            if port:
                host_no_port = host.partition(':')[0]  # Extract the host with no port supplied
                host = '{host_no_port}:{port}'.format(host_no_port=host_no_port, port=port)
            constructed_url = '//' + host + unparsed_path
            url = urlparse.urlparse(constructed_url, scheme=scheme).geturl()
        else:
            url = unparsed_path

        # Remove trailing parameter characters
        url = url[:-1] if url[-1] == '?' else url
        url = url[:-1] if url[-1] == '&' else url
        return url
401367
SamlPortConfigBuilder setSchemeAndPortIfAbsent(ServerPort serverPort) {
        requireNonNull(serverPort, "serverPort");
        if (serverPort.hasHttps()) {
            setSchemeIfAbsent(SessionProtocol.HTTPS);
        } else if (serverPort.hasHttp()) {
            setSchemeIfAbsent(SessionProtocol.HTTP);
        } else {
            throw new IllegalArgumentException("unexpected session protocol: " + serverPort.protocols());
        }

        // Do not set a port if the port number is 0 which means that the port will be automatically chosen.
        final int port = serverPort.localAddress().getPort();
        if (isValidPort(port)) {
            setPortIfAbsent(port);
        }
        return this;
    }
708839
protected function isStandardPort($scheme, $host, $port)
    {
        if (!$scheme) {
            return false;
        }

        if (!$host || !$port) {
            return true;
        }

        return (isset($this->standardSchemes[$scheme]) && $port == $this->standardSchemes[$scheme]);
    }
517591
def server_url
      @server_url ||= begin
        scheme  = request.env["rack.url_scheme"]
        address = request.env["SERVER_NAME"]
        port    = request.env["SERVER_PORT"]

        Pathname.new("#{scheme}://#{address}:#{port}")
      end
    end