Java Code Examples for io.undertow.server.HttpServerExchange#getHostPort()

The following examples show how to use io.undertow.server.HttpServerExchange#getHostPort() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UndertowHttpHandler.java    From jweb-cms with GNU Affero General Public License v3.0 5 votes vote down vote up
private URI baseURI(HttpServerExchange exchange) {
    String scheme = scheme(exchange);
    int port = exchange.getHostPort();
    StringBuilder b = new StringBuilder();
    b.append(scheme)
        .append("://")
        .append(exchange.getHostName());
    if (!("http".equals(scheme) && port == 80) && !("https".equals(scheme) && port == 443)) {
        b.append(':').append(port);
    }
    b.append('/');
    return URI.create(b.toString());
}
 
Example 2
Source File: CorsUtil.java    From light-4j with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 3
Source File: CorsUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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();
}
 
Example 4
Source File: ServletKeycloakAuthMech.java    From keycloak with Apache License 2.0 5 votes vote down vote up
protected int getConfidentilPort(HttpServerExchange exchange) {
    int confidentialPort = 8443;
    if (exchange.getRequestScheme().equalsIgnoreCase("HTTPS")) {
        confidentialPort = exchange.getHostPort();
    } else if (portManager != null) {
        confidentialPort = portManager.getConfidentialPort(exchange);
    }
    return confidentialPort;
}