HttpOperations extends ChannelOperations<INBOUND, OUTBOUND> implements HttpInfos { static void autoAddHttpExtractor(Connection c, String name, ChannelHandler handler){ if (handler instanceof ByteToMessageDecoder || handler instanceof ByteToMessageCodec || handler instanceof CombinedChannelDuplexHandler) { String extractorName = name+"$extractor"; if(c.channel().pipeline().context(extractorName) != null){ return; } c.channel().pipeline().addBefore(name, extractorName, HTTP_EXTRACTOR); if(c.isPersistent()){ c.onTerminate().subscribe(null, null, () -> c.removeHandler(extractorName)); } } } protected  HttpOperations(HttpOperations<INBOUND, OUTBOUND> replaced); protected  HttpOperations(Connection connection, ConnectionObserver listener); final boolean hasSentHeaders(); @Override boolean isWebsocket(); @Override @SuppressWarnings("unchecked") NettyOutbound send(Publisher<? extends ByteBuf> source); @Override NettyOutbound sendObject(Object message); @Override Mono<Void> then(); @Override final NettyOutbound sendFile(Path file, long position, long count); @Override String toString(); @Override HttpOperations<INBOUND, OUTBOUND> addHandler(String name, ChannelHandler handler); static String resolvePath(String uri);  }
@Test public void httpAndJsonDecoders() { EmbeddedChannel channel = new EmbeddedChannel(); Connection testContext = () -> channel; ChannelHandler handler = new JsonObjectDecoder(true); testContext.addHandlerLast("foo", handler); HttpOperations.autoAddHttpExtractor(testContext, "foo", handler); String json1 = "[{\"some\": 1} , {\"valu"; String json2 = "e\": true, \"test\": 1}]"; Object[] content = new Object[3]; content[0] = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); content[1] = new DefaultHttpContent(Unpooled.copiedBuffer(json1, CharsetUtil.UTF_8)); content[2] = new DefaultLastHttpContent(Unpooled.copiedBuffer(json2, CharsetUtil.UTF_8)); channel.writeInbound(content); Object t = channel.readInbound(); MatcherAssert.assertThat(t, instanceOf(HttpResponse.class)); MatcherAssert.assertThat(t, not(instanceOf(HttpContent.class))); t = channel.readInbound(); MatcherAssert.assertThat(t, instanceOf(ByteBuf.class)); ByteBuf b = (ByteBuf) t; MatcherAssert.assertThat(b.readCharSequence(b.readableBytes(), CharsetUtil.UTF_8), is("{\"some\": 1}")); b.release(); t = channel.readInbound(); MatcherAssert.assertThat(t, instanceOf(ByteBuf.class)); b = (ByteBuf) t; MatcherAssert.assertThat(b.readCharSequence(b.readableBytes(), CharsetUtil.UTF_8), is("{\"value\": true, \"test\": 1}")); b.release(); t = channel.readInbound(); MatcherAssert.assertThat(t, is(LastHttpContent.EMPTY_LAST_CONTENT)); ((LastHttpContent) t).release(); t = channel.readInbound(); MatcherAssert.assertThat(t, nullValue()); }