Example usage for io.netty.handler.codec.http HttpHeaderNames PROXY_CONNECTION

List of usage examples for io.netty.handler.codec.http HttpHeaderNames PROXY_CONNECTION

Introduction

In this page you can find the example usage for io.netty.handler.codec.http HttpHeaderNames PROXY_CONNECTION.

Prototype

AsciiString PROXY_CONNECTION

To view the source code for io.netty.handler.codec.http HttpHeaderNames PROXY_CONNECTION.

Click Source Link

Usage

From source file:com.otcdlink.chiron.downend.Http11ProxyHandler.java

License:Apache License

@Override
protected Object newInitialMessage(ChannelHandlerContext ctx) throws Exception {
    InetSocketAddress raddr = destinationAddress();
    String rhost;/*from  w w w . j a v a  2s.c  o  m*/
    if (raddr.isUnresolved()) {
        rhost = raddr.getHostString();
    } else {
        rhost = raddr.getAddress().getHostAddress();
    }

    FullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.CONNECT,
            rhost + ':' + raddr.getPort(), Unpooled.EMPTY_BUFFER,
            new DefaultHttpHeaders().add(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE).add(
                    HttpHeaderNames.PROXY_CONNECTION, HttpHeaderValues.KEEP_ALIVE),
            EmptyHttpHeaders.INSTANCE);

    SocketAddress proxyAddress = proxyAddress();
    if (proxyAddress instanceof InetSocketAddress) {
        InetSocketAddress hostAddr = (InetSocketAddress) proxyAddress;
        //            req.headers().set(HttpHeaderNames.HOST, hostAddr.getHostString() + ':' + hostAddr.getPort());
        req.headers().set(HttpHeaderNames.HOST, rhost + ':' + raddr.getPort());
    }

    if (authorization != null) {
        req.headers().set(HttpHeaderNames.PROXY_AUTHORIZATION, authorization);
    }

    return req;
}