@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof Http2Request) { Http2Request request = (Http2Request) msg; ctx.fireChannelRead(wrapRequest(ctx, request)); } else { ctx.fireChannelRead(msg); } }
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (msg instanceof SegmentedData) { writeContent(ctx, (SegmentedData) msg, promise); } else if (msg instanceof Response) { writeResponse(ctx, (Response) msg, promise); } else { ctx.write(msg, promise); } } }
@Override protected void configurePipeline(ChannelHandlerContext ctx, String protocol) throws Exception { if (protocol.equals(ApplicationProtocolNames.HTTP_1_1)) { replaceCodec(ctx, new HttpServerCodec()); replaceApplicationCodec(ctx, new Http1ServerCodec()); } else if (protocol.equals(ApplicationProtocolNames.HTTP_2)) { replaceCodec(ctx, http2Handler.get()); replaceApplicationCodec(ctx, new Http2ServerCodec()); } else { throw new RuntimeException("Unknown Application Protocol '" + protocol + "'"); } } }
Request request = wrapHeaders(headers, msg.streamId, msg.eos); messageSession.onInboundRequest(request); return request;
@Before public void setUp() { channel .pipeline() .addLast( "nextResponse", new ChannelOutboundHandlerAdapter() { @Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { responses.add((Http2Response) msg); outputReceived.countDown(); } }); channel.pipeline().addLast("handler", new Http2ServerCodec()); channel .pipeline() .addLast( "nextRequest", new SimpleChannelInboundHandler<Request>() { @Override protected void channelRead0(ChannelHandlerContext ctx, Request msg) { requests.add(msg); outputReceived.countDown(); } }); }