private String getRedirectHostname(final InetAddress managementAddress, final HttpServerExchange exchange) { InetAddress destinationAddress = exchange.getDestinationAddress().getAddress(); if (destinationAddress == null && exchange.getDestinationAddress().isUnresolved()) { destinationAddress = new InetSocketAddress(exchange.getDestinationAddress().getHostName(), exchange.getDestinationAddress().getPort()).getAddress();
/** * Return the host that this request was sent to, in general this will be the * value of the Host header, minus the port specifier. * <p> * If this resolves to an IPv6 address it will not be enclosed by square brackets. * Care must be taken when constructing URLs based on this method to ensure IPv6 URLs * are handled correctly. * * @return The host part of the destination address */ public String getHostName() { String host = requestHeaders.getFirst(Headers.HOST); if (host == null) { host = getDestinationAddress().getHostString(); } else { if (host.startsWith("[")) { host = host.substring(1, host.indexOf(']')); } else if (host.indexOf(':') != -1) { host = host.substring(0, host.indexOf(':')); } } return host; }
/** * Return the port that this request was sent to. In general this will be the value of the Host * header, minus the host name. * * @return The port part of the destination address */ public int getHostPort() { String host = requestHeaders.getFirst(Headers.HOST); if (host != null) { //for ipv6 addresses we make sure we take out the first part, which can have multiple occurrences of : final int colonIndex; if (host.startsWith("[")) { colonIndex = host.indexOf(':', host.indexOf(']')); } else { colonIndex = host.indexOf(':'); } if (colonIndex != -1) { try { return Integer.parseInt(host.substring(colonIndex + 1)); } catch (NumberFormatException ignore) {} } if (getRequestScheme().equals("https")) { return 443; } else if (getRequestScheme().equals("http")) { return 80; } } return getDestinationAddress().getPort(); }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { final InetSocketAddress address = exchange.getDestinationAddress(); if (address != null) { if ((resolveType == ResolveType.FORWARD || resolveType == ResolveType.FORWARD_AND_REVERSE)
/** * 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; }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { if(!exchange.getRequestHeaders().contains(Headers.HOST)) { exchange.getRequestHeaders().put(Headers.HOST, defaultHost + ":" + exchange.getDestinationAddress().getPort()); } next.handleRequest(exchange); } }
sb.append(" serverPort=" + exchange.getDestinationAddress().getPort() + "\n");
@Override public InetSocketAddress getLocalAddress() { return undertowExchange.getDestinationAddress(); }
/** * @return the inetSocketAddress * @see io.undertow.server.HttpServerExchange#getDestinationAddress() */ public InetSocketAddress getDestinationAddress() { return exchange.getDestinationAddress(); }
public InetSocketAddress getDestinationAddress() { return this.exchange.getDestinationAddress(); }
@Override public String getLocalName() { return exchange.getDestinationAddress().getHostString(); }
@Override public int getLocalPort() { return exchange.getDestinationAddress().getPort(); }
@Override public String getLocalAddr() { InetSocketAddress destinationAddress = exchange.getDestinationAddress(); if (destinationAddress == null) { return ""; } InetAddress address = destinationAddress.getAddress(); if (address == null) { //this is unresolved, so we just return the host name return destinationAddress.getHostString(); } return address.getHostAddress(); }
/** * Return the host that this request was sent to, in general this will be the * value of the Host header, minus the port specifier. * <p> * If this resolves to an IPv6 address it will not be enclosed by square brackets. * Care must be taken when constructing URLs based on this method to ensure IPv6 URLs * are handled correctly. * * @return The host part of the destination address */ public String getHostName() { String host = requestHeaders.getFirst(Headers.HOST); if (host == null) { host = getDestinationAddress().getHostString(); } else { if (host.startsWith("[")) { host = host.substring(1, host.indexOf(']')); } else if (host.indexOf(':') != -1) { host = host.substring(0, host.indexOf(':')); } } return host; }
/** * Return the host that this request was sent to, in general this will be the * value of the Host header, minus the port specifier. * <p> * If this resolves to an IPv6 address it will not be enclosed by square brackets. * Care must be taken when constructing URLs based on this method to ensure IPv6 URLs * are handled correctly. * * @return The host part of the destination address */ public String getHostName() { String host = requestHeaders.getFirst(Headers.HOST); if (host == null) { host = getDestinationAddress().getHostString(); } else { if (host.startsWith("[")) { host = host.substring(1, host.indexOf(']')); } else if (host.indexOf(':') != -1) { host = host.substring(0, host.indexOf(':')); } } return host; }
@Override final public void exchangeEvent(final HttpServerExchange exchange, final NextListener nextListener) { try { this.exchange = exchange; this.requestHeaders = exchange.getRequestHeaders(); this.destinationAddress = exchange.getDestinationAddress(); this.sourceAddress = exchange.getSourceAddress(); this.nanoStartTime = exchange.getRequestStartTime(); this.nanoEndTime = System.nanoTime(); this.logDateTime = LocalDateTime.now(); logger.accept(this); } finally { nextListener.proceed(); } }
/** * 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; }
/** * 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; }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { if(!exchange.getRequestHeaders().contains(Headers.HOST)) { exchange.getRequestHeaders().put(Headers.HOST, defaultHost + ":" + exchange.getDestinationAddress().getPort()); } next.handleRequest(exchange); } }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { if(!exchange.getRequestHeaders().contains(Headers.HOST)) { exchange.getRequestHeaders().put(Headers.HOST, defaultHost + ":" + exchange.getDestinationAddress().getPort()); } next.handleRequest(exchange); } }