Skip to content

Commit

Permalink
#66 tidy up initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
robfletcher committed Aug 8, 2013
1 parent 8f29857 commit 4fbcf87
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package co.freeside.betamax.proxy.netty;

import javax.net.ssl.*;
import co.freeside.betamax.proxy.netty.ssl.*;
import io.netty.channel.*;
import io.netty.channel.nio.*;
import io.netty.channel.socket.*;
import io.netty.handler.codec.http.*;
import io.netty.handler.ssl.*;
import io.netty.handler.stream.*;

/**
Expand All @@ -13,12 +16,10 @@ public class HttpChannelInitializer extends ChannelInitializer<SocketChannel> {

public static final int MAX_CONTENT_LENGTH = 65536;

private final int workerThreads;
private final ChannelHandler handler;
private final EventLoopGroup workerGroup;

public HttpChannelInitializer(int workerThreads, ChannelHandler handler) {
this.workerThreads = workerThreads;
this.handler = handler;

if (workerThreads > 0) {
Expand All @@ -31,15 +32,19 @@ public HttpChannelInitializer(int workerThreads, ChannelHandler handler) {
@Override
public void initChannel(SocketChannel channel) throws Exception {
ChannelPipeline pipeline = channel.pipeline();
pipeline
.addLast(new HttpRequestDecoder())
.addLast(new HttpObjectAggregator(MAX_CONTENT_LENGTH))
.addLast(new HttpResponseEncoder())
.addLast(new ChunkedWriteHandler());

// SSLEngine engine = SslContextFactory.getServerContext().createSSLEngine();
// engine.setUseClientMode(false);

// pipeline.addLast("ssl", new SslHandler(engine));
pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("aggregator", new HttpObjectAggregator(MAX_CONTENT_LENGTH));
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
if (workerGroup == null) {
pipeline.addLast(handler);
pipeline.addLast("betamaxHandler", handler);
} else {
pipeline.addLast(workerGroup, handler);
pipeline.addLast(workerGroup, "betamaxHandler", handler);
}
}
}

0 comments on commit 4fbcf87

Please sign in to comment.