Java
기타

Netty HTTP Client / 요청을 보낸 URL을 채널 핸들러에서 가져오기

no

noeul
질문 종료
30 XP
Channel future = new Bootstrap()
        .group(new NioEventLoopGroup())
        .channel(NioSocketChannel.class)
        .handler(new ChannelInitializer<SocketChannel>() {
            @Override
            protected void initChannel(SocketChannel channel) throws Exception {
                channel.pipeline()
                        .addLast("ssl", SslContextBuilder.forClient()
                                .trustManager(InsecureTrustManagerFactory.INSTANCE)
                                .build()
                                .newHandler(channel.alloc(), "example.com", 443)
                        )
                        .addLast("http_codec", new HttpClientCodec())
                        .addLast("handler", new ChannelInboundHandlerAdapter() {
                            @Override
                            public void channelRead(@NotNull ChannelHandlerContext ctx, @NotNull Object msg) throws Exception {
                                // ...
                            }
                        });
            }
        })
        .option(ChannelOption.TCP_NODELAY, true)
        .option(ChannelOption.SO_KEEPALIVE, true)
        .connect("example.com", 443)
        .syncUninterruptibly()
        .channel();
DefaultHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/api/get");
request.headers()
        .set(HttpHeaderNames.HOST, "example.com")
        .set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
channel.writeAndFlush(request);

특정 URL(예시에서는 /api/get)로 요청을 보냈을때, 이름이 handler인 HttpObject 핸들러의 channelRead 메소드에서 그 URL을 어떻게 get할 수 있을까욘


불러오는 중...