/** * Determine the default origin, to allow for local access. * @param exchange the current HttpExchange. * @return the default origin (aka current server). */ public static String defaultOrigin(HttpServerExchange exchange) { String host = NetworkUtils.formatPossibleIpv6Address(exchange.getHostName()); String protocol = exchange.getRequestScheme(); int port = exchange.getHostPort(); //This browser set header should not need IPv6 escaping StringBuilder allowedOrigin = new StringBuilder(256); allowedOrigin.append(protocol).append("://").append(host); if (!isDefaultPort(port, protocol)) { allowedOrigin.append(':').append(port); } return allowedOrigin.toString(); }
exchange.setSourceAddress(new InetSocketAddress(NetworkUtils.parseIpv4Address(remoteClient), 0)); } else if(IP6_EXACT.matcher(forwardedFor).matches()) { exchange.setSourceAddress(new InetSocketAddress(NetworkUtils.parseIpv6Address(remoteClient), 0)); } else { exchange.setSourceAddress(InetSocketAddress.createUnresolved(remoteClient, 0)); String hostHeader = NetworkUtils.formatPossibleIpv6Address(value); if(forwardedPort != null) { try {
static InetAddress parseAddress(String addressString, String protocol) throws IOException { if (protocol.equals(TCP4)) { return NetworkUtils.parseIpv4Address(addressString); } else { return NetworkUtils.parseIpv6Address(addressString); } }
return new InetSocketAddress(NetworkUtils.parseIpv6Address(ipPart), 0); } else { return new InetSocketAddress(NetworkUtils.parseIpv6Address(ipPart), parsePort(address.substring(pos + 1))); return new InetSocketAddress(NetworkUtils.parseIpv4Address(address), 0); } else { return new InetSocketAddress(NetworkUtils.parseIpv4Address(address.substring(0, pos)), parsePort(address.substring(pos + 1)));
.append("Digest: ").append(digestString).append(CRLF) .append("Server: ").append(server).append(CRLF) .append("X-Manager-Address: ").append(NetworkUtils.formatPossibleIpv6Address(host)).append(":").append(port).append(CRLF) .append("X-Manager-Url: ").append(path).append(CRLF) .append("X-Manager-Protocol: ").append(protocol).append(CRLF)
exchange.setSourceAddress(new InetSocketAddress(NetworkUtils.parseIpv4Address(remoteClient), 0)); } else if(IP6_EXACT.matcher(forwardedFor).matches()) { exchange.setSourceAddress(new InetSocketAddress(NetworkUtils.parseIpv6Address(remoteClient), 0)); } else { exchange.setSourceAddress(InetSocketAddress.createUnresolved(remoteClient, 0)); String hostHeader = NetworkUtils.formatPossibleIpv6Address(value); if(forwardedPort != null) { try {
static InetAddress parseAddress(String addressString, String protocol) throws IOException { if (protocol.equals(TCP4)) { return NetworkUtils.parseIpv4Address(addressString); } else { return NetworkUtils.parseIpv6Address(addressString); } }
/** * Return the host, and also the port if this request was sent to a non-standard port. In general * this will just be the value of the Host header. * <p> * If this resolves to an IPv6 address it *will* be enclosed by square brackets. The return * value of this method is suitable for inclusion in a URL. * * @return The host and port part of the destination address */ public String getHostAndPort() { String host = requestHeaders.getFirst(Headers.HOST); if (host == null) { InetSocketAddress address = getDestinationAddress(); host = NetworkUtils.formatPossibleIpv6Address(address.getHostString()); int port = address.getPort(); if (!((getRequestScheme().equals("http") && port == 80) || (getRequestScheme().equals("https") && port == 443))) { host = host + ":" + port; } } return host; }
exchange.setSourceAddress(new InetSocketAddress(NetworkUtils.parseIpv4Address(remoteClient), 0)); } else if(IP6_EXACT.matcher(forwardedFor).matches()) { exchange.setSourceAddress(new InetSocketAddress(NetworkUtils.parseIpv6Address(remoteClient), 0)); } else { exchange.setSourceAddress(InetSocketAddress.createUnresolved(remoteClient, 0)); String hostHeader = NetworkUtils.formatPossibleIpv6Address(value); if(forwardedPort != null) { try {
static InetAddress parseAddress(String addressString, String protocol) throws IOException { if (protocol.equals(TCP4)) { return NetworkUtils.parseIpv4Address(addressString); } else { return NetworkUtils.parseIpv6Address(addressString); } }
final String hostName = exchange.getHostName(); if(hostName != null) { request.getRequestHeaders().put(Headers.X_FORWARDED_HOST, NetworkUtils.formatPossibleIpv6Address(hostName));
return new InetSocketAddress(NetworkUtils.parseIpv6Address(ipPart), 0); } else { return new InetSocketAddress(NetworkUtils.parseIpv6Address(ipPart), parsePort(address.substring(pos + 1))); return new InetSocketAddress(NetworkUtils.parseIpv4Address(address), 0); } else { return new InetSocketAddress(NetworkUtils.parseIpv4Address(address.substring(0, pos)), parsePort(address.substring(pos + 1)));
/** * Creates an initialized connection config instance. * In the current implementation, protocol and host can't be null. * * @param protocol protocol to use for the discovery * @param host host name of the domain controller * @param port port number of the domain controller */ public RemoteDomainControllerConnectionConfiguration(String protocol, String host, int port) { assert protocol != null : "protocol is null"; assert host != null : "host is null"; remoteDcHost = NetworkUtils.formatPossibleIpv6Address(host); remoteDcPort = port; remoteDcProtocol = protocol; }
return new InetSocketAddress(NetworkUtils.parseIpv6Address(ipPart), 0); } else { return new InetSocketAddress(NetworkUtils.parseIpv6Address(ipPart), parsePort(address.substring(pos + 1))); return new InetSocketAddress(NetworkUtils.parseIpv4Address(address), 0); } else { return new InetSocketAddress(NetworkUtils.parseIpv4Address(address.substring(0, pos)), parsePort(address.substring(pos + 1)));
/** * Creates an initialized connection config instance. * In the current implementation, protocol and host can't be null. * * @param protocol protocol to use for the discovery * @param host host name of the domain controller * @param port port number of the domain controller */ public RemoteDomainControllerConnectionConfiguration(String protocol, String host, int port) { assert protocol != null : "protocol is null"; assert host != null : "host is null"; remoteDcHost = NetworkUtils.formatPossibleIpv6Address(host); remoteDcPort = port; remoteDcProtocol = protocol; }
/** * Determine the default origin, to allow for local access. * @param exchange the current HttpExchange. * @return the default origin (aka current server). */ public static String defaultOrigin(HttpServerExchange exchange) { String host = NetworkUtils.formatPossibleIpv6Address(exchange.getHostName()); String protocol = exchange.getRequestScheme(); int port = exchange.getHostPort(); //This browser set header should not need IPv6 escaping StringBuilder allowedOrigin = new StringBuilder(256); allowedOrigin.append(protocol).append("://").append(host); if (!isDefaultPort(port, protocol)) { allowedOrigin.append(':').append(port); } return allowedOrigin.toString(); }
/** * Return the host, and also the port if this request was sent to a non-standard port. In general * this will just be the value of the Host header. * <p> * If this resolves to an IPv6 address it *will* be enclosed by square brackets. The return * value of this method is suitable for inclusion in a URL. * * @return The host and port part of the destination address */ public String getHostAndPort() { String host = requestHeaders.getFirst(Headers.HOST); if (host == null) { InetSocketAddress address = getDestinationAddress(); host = NetworkUtils.formatPossibleIpv6Address(address.getHostString()); int port = address.getPort(); if (!((getRequestScheme().equals("http") && port == 80) || (getRequestScheme().equals("https") && port == 443))) { host = host + ":" + port; } } return host; }
.append("Digest: ").append(digestString).append(CRLF) .append("Server: ").append(server).append(CRLF) .append("X-Manager-Address: ").append(NetworkUtils.formatPossibleIpv6Address(host)).append(":").append(port).append(CRLF) .append("X-Manager-Url: ").append(path).append(CRLF) .append("X-Manager-Protocol: ").append(protocol).append(CRLF)
/** * Return the host, and also the port if this request was sent to a non-standard port. In general * this will just be the value of the Host header. * <p> * If this resolves to an IPv6 address it *will* be enclosed by square brackets. The return * value of this method is suitable for inclusion in a URL. * * @return The host and port part of the destination address */ public String getHostAndPort() { String host = requestHeaders.getFirst(Headers.HOST); if (host == null) { InetSocketAddress address = getDestinationAddress(); host = NetworkUtils.formatPossibleIpv6Address(address.getHostString()); int port = address.getPort(); if (!((getRequestScheme().equals("http") && port == 80) || (getRequestScheme().equals("https") && port == 443))) { host = host + ":" + port; } } return host; }
.append("Digest: ").append(digestString).append(CRLF) .append("Server: ").append(server).append(CRLF) .append("X-Manager-Address: ").append(NetworkUtils.formatPossibleIpv6Address(host)).append(":").append(port).append(CRLF) .append("X-Manager-Url: ").append(path).append(CRLF) .append("X-Manager-Protocol: ").append(protocol).append(CRLF)