HttpSnoopClient Class — netty Architecture
Architecture documentation for the HttpSnoopClient class in HttpSnoopClient.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 449b073a_eb78_55c5_d393_4d3f1dc5efdc["HttpSnoopClient"] 182463f3_c73a_ce46_a209_d0837c35b653["HttpSnoopClient.java"] 449b073a_eb78_55c5_d393_4d3f1dc5efdc -->|defined in| 182463f3_c73a_ce46_a209_d0837c35b653 228ce974_1294_fd6a_f948_b4801b9384f1["main()"] 449b073a_eb78_55c5_d393_4d3f1dc5efdc -->|method| 228ce974_1294_fd6a_f948_b4801b9384f1
Relationship Graph
Source Code
example/src/main/java/io/netty/example/http/snoop/HttpSnoopClient.java lines 43–110
public final class HttpSnoopClient {
static final String URL = System.getProperty("url", "http://127.0.0.1:8080/");
public static void main(String[] args) throws Exception {
URI uri = new URI(URL);
String scheme = uri.getScheme() == null? "http" : uri.getScheme();
String host = uri.getHost() == null? "127.0.0.1" : uri.getHost();
int port = uri.getPort();
if (port == -1) {
if ("http".equalsIgnoreCase(scheme)) {
port = 80;
} else if ("https".equalsIgnoreCase(scheme)) {
port = 443;
}
}
if (!"http".equalsIgnoreCase(scheme) && !"https".equalsIgnoreCase(scheme)) {
System.err.println("Only HTTP(S) is supported.");
return;
}
// Configure SSL context if necessary.
final boolean ssl = "https".equalsIgnoreCase(scheme);
final SslContext sslCtx;
if (ssl) {
sslCtx = SslContextBuilder.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE).build();
} else {
sslCtx = null;
}
// Configure the client.
EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
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();
// Prepare the HTTP request.
HttpRequest request = new DefaultFullHttpRequest(
HttpVersion.HTTP_1_1, HttpMethod.GET, uri.getRawPath(), Unpooled.EMPTY_BUFFER);
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();
}
}
}
Source
Frequently Asked Questions
What is the HttpSnoopClient class?
HttpSnoopClient is a class in the netty codebase, defined in example/src/main/java/io/netty/example/http/snoop/HttpSnoopClient.java.
Where is HttpSnoopClient defined?
HttpSnoopClient is defined in example/src/main/java/io/netty/example/http/snoop/HttpSnoopClient.java at line 43.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free