// Configure the client.
EventLoopGroup group = new NioEventLoopGroup();
try {
Bootstrap b = new Bootstrap();
//b.group(group)
// .channel(NioSocketChannel.class)
// .handler(new HttpSnoopClientInitializer(sslCtx));
//
//// Make the connection attempt.
//Channel ch = b.connect(host, port).sync().channel();
b.group(group).channel(NioSocketChannel.class).handler(new HttpSnoopClientInitializer(sslCtx)).remoteAddress(host, port);
CountingChannelPoolHandler handler = new CountingChannelPoolHandler(); // CountingChannelPoolHandler is copied from netty test!
SimpleChannelPool pool = new SimpleChannelPool(b, handler);
Channel ch = pool.acquire().sync().getNow();
// Prepare the HTTP request.
HttpRequest request = new DefaultFullHttpRequest(
HttpVersion.HTTP_1_1, HttpMethod.GET, uri.getRawPath());
request.headers().set(HttpHeaderNames.HOST, host);
request.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
request.headers().set(HttpHeaderNames.ACCEPT_ENCODING, HttpHeaderValues.GZIP);
// Set some example cookies.
request.headers().set(
HttpHeaderNames.COOKIE,
ClientCookieEncoder.STRICT.encode(
new DefaultCookie("my-cookie", "foo"),
new DefaultCookie("another-cookie", "bar")));
// Send the HTTP request.
ch.writeAndFlush(request);
// Wait for the server to close the connection.
ch.closeFuture().sync();
} finally {
// Shut down executor threads to exit.
group.shutdownGracefully();
}