use of io.netty.handler.stream.ChunkedWriteHandler in project BRFS by zhangnianli.
the class NettyChannelInitializer method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// server端发送的是httpResponse,所以要使用HttpResponseEncoder进行编码
pipeline.addLast(new HttpResponseEncoder());
// server端接收到的是httpRequest,所以要使用HttpRequestDecoder进行解码
pipeline.addLast(new HttpRequestDecoder());
pipeline.addLast(new HttpObjectAggregator(65536));
pipeline.addLast(new ChunkedWriteHandler());
contextHandlers.forEach((NettyHttpContextHandler handler) -> pipeline.addLast(handler));
}
use of io.netty.handler.stream.ChunkedWriteHandler in project BRFS by zhangnianli.
the class NettyChannelInitializer method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// server端发送的是httpResponse,所以要使用HttpResponseEncoder进行编码
pipeline.addLast(new HttpResponseEncoder());
// server端接收到的是httpRequest,所以要使用HttpRequestDecoder进行解码
pipeline.addLast(new HttpRequestDecoder());
pipeline.addLast(new HttpObjectAggregator(65536));
pipeline.addLast(new ChunkedWriteHandler());
contextHandlers.forEach((NettyHttpContextHandler handler) -> pipeline.addLast(handler));
}
use of io.netty.handler.stream.ChunkedWriteHandler in project jdepth by Crab2died.
the class WebSocketServer method run.
private void run(int port) throws InterruptedException {
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap bootstrap = new ServerBootstrap().channel(NioServerSocketChannel.class).group(bossGroup, workerGroup).handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast("http-codec", new HttpServerCodec()).addLast("aggregator", new HttpObjectAggregator(65536)).addLast("http-chunked", new ChunkedWriteHandler()).addLast("handler", new WebSocketServerHandler());
}
});
Channel channel = bootstrap.bind(port).sync().channel();
channel.closeFuture().sync();
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
use of io.netty.handler.stream.ChunkedWriteHandler in project duangframework by tcrct.
the class HttpChannelInitializer method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
if (bootStrap.isSslEnabled()) {
sslContext = bootStrap.getSslContext();
}
// HttpServerCodec包含了默认的HttpRequestDecoder(请求消息解码器)和HttpResponseEncoder(响应解码器)
p.addLast(new HttpServerCodec());
// 为http响应内容添加gizp压缩器
p.addLast(new HttpContentCompressor());
// 目的是将多个消息转换为单一的request或者response对象
p.addLast(new HttpObjectAggregator(1048576));
// 目的是支持异步大文件传输
p.addLast(new ChunkedWriteHandler());
// 真正处理HTTP业务逻辑的地方,针对每个TCP连接创建一个新的ChannelHandler实例
p.addLast(new HttpBaseHandler(bootStrap));
}
use of io.netty.handler.stream.ChunkedWriteHandler in project jackrabbit-oak by apache.
the class GetBlobResponseEncoderTest method shouldEncodeTwoChunksResponse.
@Test
public void shouldEncodeTwoChunksResponse() throws Exception {
byte[] blobData = new byte[] { 1, 2, 3, 4 };
byte[] firstChunkData = new byte[] { 1, 2 };
byte[] secondChunkbData = new byte[] { 3, 4 };
String blobId = "blobId";
EmbeddedChannel channel = new EmbeddedChannel(new ChunkedWriteHandler(), new GetBlobResponseEncoder(2));
channel.writeOutbound(new GetBlobResponse("clientId", blobId, new ByteArrayInputStream(blobData), blobData.length));
ByteBuf firstBuffer = (ByteBuf) channel.readOutbound();
byte firstMask = createMask(1, 2);
ByteBuf firstExpected = createBlobChunkBuffer(Messages.HEADER_BLOB, 4L, blobId, firstChunkData, firstMask);
assertEquals(firstExpected, firstBuffer);
ByteBuf secondBuffer = (ByteBuf) channel.readOutbound();
byte secondMask = createMask(2, 2);
ByteBuf secondExpected = createBlobChunkBuffer(Messages.HEADER_BLOB, 4L, blobId, secondChunkbData, secondMask);
assertEquals(secondExpected, secondBuffer);
}
Aggregations