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

The following examples show how to use io.undertow.server.HttpServerExchange#setDestinationAddress() . 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: ForwardedHandler.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    List<String> forwarded = exchange.getRequestHeaders(HttpHeaderNames.FORWARDED);
    if (forwarded != null) {
        Map<Token, String> values = new HashMap<>();
        for (String val : forwarded) {
            parseHeader(val, values);
        }
        String host = values.get(Token.HOST);
        String proto = values.get(Token.PROTO);
        String by = values.get(Token.BY);
        String forVal = values.get(Token.FOR);

        if (host != null) {
            exchange.setRequestHeader(HttpHeaderNames.HOST, host);
            exchange.setDestinationAddress(InetSocketAddress.createUnresolved(exchange.getHostName(), exchange.getHostPort()));
        } else if (by != null) {
            //we only use 'by' if the host is null
            InetSocketAddress destAddress = parseAddress(by);
            if (destAddress != null) {
                exchange.setDestinationAddress(destAddress);
            }
        }
        if (proto != null) {
            exchange.setRequestScheme(proto);
        }
        if (forVal != null) {
            InetSocketAddress sourceAddress = parseAddress(forVal);
            if (sourceAddress != null) {
                exchange.setSourceAddress(sourceAddress);
            }
        }
    }


    next.handleRequest(exchange);
}
 
Example 2
Source File: ForwardedHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    HeaderValues forwarded = exchange.getRequestHeaders().get(Headers.FORWARDED);
    if (forwarded != null) {
        Map<Token, String> values = new HashMap<>();
        for (String val : forwarded) {
            parseHeader(val, values);
        }
        String host = values.get(Token.HOST);
        String proto = values.get(Token.PROTO);
        String by = values.get(Token.BY);
        String forVal = values.get(Token.FOR);

        if (host != null) {
            exchange.getRequestHeaders().put(Headers.HOST, host);
            exchange.setDestinationAddress(InetSocketAddress.createUnresolved(exchange.getHostName(), exchange.getHostPort()));
        } else if (by != null) {
            //we only use 'by' if the host is null
            InetSocketAddress destAddress = parseAddress(by);
            if (destAddress != null) {
                exchange.setDestinationAddress(destAddress);
            }
        }
        if (proto != null) {
            exchange.setRequestScheme(proto);
        }
        if (forVal != null) {
            InetSocketAddress sourceAddress = parseAddress(forVal);
            if (sourceAddress != null) {
                exchange.setSourceAddress(sourceAddress);
            }
        }
    }


    next.handleRequest(exchange);
}
 
Example 3
Source File: TracingHandlerTest.java    From skywalking with Apache License 2.0 5 votes vote down vote up
private HttpServerExchange buildExchange() {
    HeaderMap requestHeaders = new HeaderMap();
    HeaderMap responseHeaders = new HeaderMap();
    HttpServerExchange exchange = new HttpServerExchange(serverConnection, requestHeaders, responseHeaders, 0);
    exchange.setRequestURI(uri);
    exchange.setRequestPath(uri);
    exchange.setDestinationAddress(new InetSocketAddress("localhost", 8080));
    exchange.setRequestScheme("http");
    exchange.setRequestMethod(Methods.GET);
    return exchange;
}
 
Example 4
Source File: RoutingHandlerInterceptorTest.java    From skywalking with Apache License 2.0 5 votes vote down vote up
private HttpServerExchange buildExchange() {
    HeaderMap requestHeaders = new HeaderMap();
    HeaderMap responseHeaders = new HeaderMap();
    HttpServerExchange exchange = new HttpServerExchange(serverConnection, requestHeaders, responseHeaders, 0);
    exchange.setRequestURI(uri);
    exchange.setRequestPath(uri);
    exchange.setDestinationAddress(new InetSocketAddress("localhost", 8080));
    exchange.setRequestScheme("http");
    exchange.setRequestMethod(Methods.GET);
    return exchange;
}