private final boolean client;
/**
* @param client
*/
public HttpPipelindeInitializer(boolean client) {
this.client = client;
}
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
if (client) {
pipeline.addLast("decoder",new HttpResponseDecoder());//如果是客户端,则添加HttpResponseDecoder以处理来自服务器的响应!
pipeline.addLast("encoder",new HttpResponseEncoder());//如果是客户端,则添加HttpRequestEncoder以向服务器发送请求。
} else {
pipeline.addLast("decoder",new HttpRequestDecoder());//如果是服务器,则添加HttpRequestEncoder以向客户端发送响应。
pipeline.addLast("encoder",new HttpRequestEncoder());//如果是服务器,则添加HttpRequestDecoder以接受来自客户端的请求
}
/**
* @param client
*/
public HttpPipelindeInitializer(boolean client) {
this.client = client;
}
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
if (client) {
pipeline.addLast("decoder",new HttpResponseDecoder());//如果是客户端,则添加HttpResponseDecoder以处理来自服务器的响应!
pipeline.addLast("encoder",new HttpResponseEncoder());//如果是客户端,则添加HttpRequestEncoder以向服务器发送请求。
} else {
pipeline.addLast("decoder",new HttpRequestDecoder());//如果是服务器,则添加HttpRequestEncoder以向客户端发送响应。
pipeline.addLast("encoder",new HttpRequestEncoder());//如果是服务器,则添加HttpRequestDecoder以接受来自客户端的请求
}
}
Http聚合
public class HttpAggregatorInitial