if (msg instanceof Http2DataFrame) { Http2DataFrame dataFrame = (Http2DataFrame) msg; encoder().writeData(ctx, dataFrame.stream().id(), dataFrame.content(), dataFrame.padding(), dataFrame.isEndStream(), promise); } else if (msg instanceof Http2HeadersFrame) { writeHeadersFrame(ctx, (Http2HeadersFrame) msg, promise);
@Override public int size(Object msg) { return msg instanceof Http2DataFrame ? // Guard against overflow. (int) min(Integer.MAX_VALUE, ((Http2DataFrame) msg).initialFlowControlledBytes() + (long) MIN_HTTP2_FRAME_SIZE) : MIN_HTTP2_FRAME_SIZE; } };
/** * Process incoming data. */ private void onDataRead(ChannelHandlerContext ctx, Http2DataFrame data) throws Exception { isList.add(new ByteBufInputStream(data.content())); if (data.isEndStream()) { isList.add(NettyInputStream.END_OF_INPUT); } }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof Http2StreamFrame) { // Handle HTTP/2 clear text upgrade request if (msg instanceof Http2HeadersFrame) { Http2HeadersFrame frame = (Http2HeadersFrame) msg; connection.onHeadersRead(ctx, 1, frame.headers(), frame.padding(), frame.isEndStream()); } else if (msg instanceof Http2DataFrame) { Http2DataFrame frame = (Http2DataFrame) msg; connection.onDataRead(ctx, 1, frame.content(), frame.padding(), frame.isEndStream()); } } else { super.channelRead(ctx, msg); } }
session.onInboundResponse( new SegmentedResponseData( resp, new Http2SegmentedData(frame.content(), msg.eos, streamId)))) .orElse(null); } else {
protected boolean isEndOfRequestResponse(Object msg) { if (msg instanceof Http2HeadersFrame) { return ((Http2HeadersFrame) msg).isEndStream(); } if (msg instanceof Http2DataFrame) { return ((Http2DataFrame) msg).isEndStream(); } return false; }
if (dataFrame.isEndStream()) { out.add(new DefaultLastHttpContent(dataFrame.content().retain(), validateHeaders)); } else { out.add(new DefaultHttpContent(dataFrame.content().retain()));
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof Http2StreamFrame) { // Handle HTTP/2 clear text upgrade request if (msg instanceof Http2HeadersFrame) { Http2HeadersFrame frame = (Http2HeadersFrame) msg; connection.onHeadersRead(ctx, 1, frame.headers(), frame.padding(), frame.isEndStream()); } else if (msg instanceof Http2DataFrame) { Http2DataFrame frame = (Http2DataFrame) msg; connection.onDataRead(ctx, 1, frame.content(), frame.padding(), frame.isEndStream()); } } else { super.channelRead(ctx, msg); } }
@Test public void testFullRequestWithBody() throws Exception { outputReceived = new CountDownLatch(1); ByteBuf body = ByteBufUtil.writeUtf8(UnpooledByteBufAllocator.DEFAULT, "body"); FullRequest requestIn = RequestBuilders.newPost("/").host("localhost").body(body).build(); channel.writeOutbound(requestIn); channel.runPendingTasks(); // blocks Uninterruptibles.awaitUninterruptibly(outputReceived); Http2Request requestOut = (Http2Request) requests.remove(0); assertTrue(requestOut != null); assertTrue(requestOut.payload instanceof Http2Headers); assertEquals("POST", ((Http2Headers) requestOut.payload).method().toString()); assertEquals("/", ((Http2Headers) requestOut.payload).path()); assertFalse(requestOut.eos); Http2Request contentOut = (Http2Request) requests.remove(0); assertTrue(contentOut != null); assertTrue(contentOut.payload instanceof Http2DataFrame); assertEquals(body, ((Http2DataFrame) contentOut.payload).content()); assertTrue(contentOut.eos); }
protected boolean isEndOfRequestResponse(Object msg) { if (msg instanceof Http2HeadersFrame) { return ((Http2HeadersFrame) msg).isEndStream(); } if (msg instanceof Http2DataFrame) { return ((Http2DataFrame) msg).isEndStream(); } return false; }
if (msg instanceof Http2DataFrame) { Http2DataFrame dataFrame = (Http2DataFrame) msg; encoder().writeData(ctx, dataFrame.stream().id(), dataFrame.content(), dataFrame.padding(), dataFrame.isEndStream(), promise); } else if (msg instanceof Http2HeadersFrame) { writeHeadersFrame(ctx, (Http2HeadersFrame) msg, promise);
private void onDataRead(Http2DataFrame dataFrame, ChannelHandlerContext ctx) throws Http2Exception { ByteBuf data = dataFrame.content(); data.retain(); if (!dataFrame.isEndStream()) { ctx.fireChannelRead(new DefaultHttpContent(data)); } else { ctx.fireChannelRead(new DefaultLastHttpContent(data)); } }
assertFalse(((Http2DataFrame) bodyOut1.payload).content() == null); assertEquals(body1, ((Http2DataFrame) bodyOut1.payload).content()); assertFalse(bodyOut1.eos); assertFalse(((Http2DataFrame) bodyOut2.payload).content() == null); assertEquals(body2, ((Http2DataFrame) bodyOut2.payload).content()); assertTrue(bodyOut2.eos);
protected boolean isEndOfRequestResponse(Object msg) { if (msg instanceof Http2HeadersFrame) { return ((Http2HeadersFrame) msg).isEndStream(); } if (msg instanceof Http2DataFrame) { return ((Http2DataFrame) msg).isEndStream(); } return false; }
@SuppressWarnings("deprecation") void doRead0(Http2Frame frame, Handle allocHandle) { pipeline().fireChannelRead(frame); allocHandle.incMessagesRead(1); if (frame instanceof Http2DataFrame) { final int numBytesToBeConsumed = ((Http2DataFrame) frame).initialFlowControlledBytes(); allocHandle.attemptedBytesRead(numBytesToBeConsumed); allocHandle.lastBytesRead(numBytesToBeConsumed); if (numBytesToBeConsumed != 0) { try { writeDoneAndNoFlush |= onBytesConsumed(ctx, stream, numBytesToBeConsumed); } catch (Http2Exception e) { pipeline().fireExceptionCaught(e); } } } else { allocHandle.attemptedBytesRead(MIN_HTTP2_FRAME_SIZE); allocHandle.lastBytesRead(MIN_HTTP2_FRAME_SIZE); } }
if (msg instanceof Http2DataFrame) { Http2DataFrame dataFrame = (Http2DataFrame) msg; encoder().writeData(ctx, dataFrame.stream().id(), dataFrame.content(), dataFrame.padding(), dataFrame.isEndStream(), promise); } else if (msg instanceof Http2HeadersFrame) { writeHeadersFrame(ctx, (Http2HeadersFrame) msg, promise);
private void onDataRead(Http2DataFrame dataFrame, ChannelHandlerContext ctx) throws Http2Exception { ByteBuf data = dataFrame.content(); data.retain(); if (!dataFrame.isEndStream()) { ctx.fireChannelRead(new DefaultHttpContent(data)); } else { ctx.fireChannelRead(new DefaultLastHttpContent(data)); } }
SegmentedRequestData data = new SegmentedRequestData( initialRequest, new Http2SegmentedData(frame.content(), msg.eos, msg.streamId)); messageSession.onInboundRequestData(data); return data;
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { if (msg instanceof Http2Headers) { msg = new DefaultHttp2HeadersFrame((Http2Headers) msg); } boolean endOfHttp2Stream = false; if (msg instanceof Http2DataFrame) { endOfHttp2Stream = ((Http2DataFrame) msg).isEndStream(); } if (!endOfHttp2Stream && msg instanceof ByteBuf && ctx.channel() instanceof Http2StreamChannel) { msg = new DefaultHttp2DataFrame((ByteBuf) msg); } ctx.write(msg, promise); }
@Override public int size(Object msg) { return msg instanceof Http2DataFrame ? // Guard against overflow. (int) min(Integer.MAX_VALUE, ((Http2DataFrame) msg).initialFlowControlledBytes() + (long) MIN_HTTP2_FRAME_SIZE) : MIN_HTTP2_FRAME_SIZE; } };