Http Transport: Allow to configure `max_header_size`, `max_initial_line_length`, and `max_chunk_size`, closes #1174.

This commit is contained in:
Shay Banon 2011-07-28 18:32:38 +03:00
parent 7e0182d882
commit 615fc435cc
1 changed files with 45 additions and 24 deletions

View File

@ -82,13 +82,16 @@ public class NettyHttpServerTransport extends AbstractLifecycleComponent<HttpSer
private final NetworkService networkService;
private final ByteSizeValue maxContentLength;
final ByteSizeValue maxContentLength;
final ByteSizeValue maxInitialLineLength;
final ByteSizeValue maxHeaderSize;
final ByteSizeValue maxChunkSize;
private final int workerCount;
private final boolean blockingServer;
private final boolean compression;
final boolean compression;
private final int compressionLevel;
@ -114,7 +117,7 @@ public class NettyHttpServerTransport extends AbstractLifecycleComponent<HttpSer
private volatile Channel serverChannel;
private volatile OpenChannelsHandler serverOpenChannels;
OpenChannelsHandler serverOpenChannels;
private volatile HttpServerAdapter httpServerAdapter;
@ -122,6 +125,9 @@ public class NettyHttpServerTransport extends AbstractLifecycleComponent<HttpSer
super(settings);
this.networkService = networkService;
ByteSizeValue maxContentLength = componentSettings.getAsBytesSize("max_content_length", settings.getAsBytesSize("http.max_content_length", new ByteSizeValue(100, ByteSizeUnit.MB)));
this.maxChunkSize = componentSettings.getAsBytesSize("max_chunk_size", settings.getAsBytesSize("http.max_chunk_size", new ByteSizeValue(8, ByteSizeUnit.KB)));
this.maxHeaderSize = componentSettings.getAsBytesSize("max_header_size", settings.getAsBytesSize("http.max_header_size", new ByteSizeValue(8, ByteSizeUnit.KB)));
this.maxInitialLineLength = componentSettings.getAsBytesSize("max_initial_line_length", settings.getAsBytesSize("http.max_initial_line_length", new ByteSizeValue(4, ByteSizeUnit.KB)));
this.workerCount = componentSettings.getAsInt("worker_count", Runtime.getRuntime().availableProcessors() * 2);
this.blockingServer = settings.getAsBoolean("http.blocking_server", settings.getAsBoolean(TCP_BLOCKING_SERVER, settings.getAsBoolean(TCP_BLOCKING, false)));
this.port = componentSettings.get("port", settings.get("http.port", "9200-9300"));
@ -142,6 +148,9 @@ public class NettyHttpServerTransport extends AbstractLifecycleComponent<HttpSer
maxContentLength = new ByteSizeValue(100, ByteSizeUnit.MB);
}
this.maxContentLength = maxContentLength;
logger.debug("using max_chunk_size[{}], max_header_size[{}], max_initial_line_length[{}], max_content_length[{}]",
maxChunkSize, maxHeaderSize, maxInitialLineLength, this.maxContentLength);
}
public void httpServerAdapter(HttpServerAdapter httpServerAdapter) {
@ -163,27 +172,7 @@ public class NettyHttpServerTransport extends AbstractLifecycleComponent<HttpSer
workerCount));
}
final HttpRequestHandler requestHandler = new HttpRequestHandler(this);
ChannelPipelineFactory pipelineFactory = new ChannelPipelineFactory() {
@Override public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("openChannels", serverOpenChannels);
pipeline.addLast("decoder", new HttpRequestDecoder());
if (compression) {
pipeline.addLast("decoder_compress", new HttpContentDecompressor());
}
pipeline.addLast("aggregator", new HttpChunkAggregator((int) maxContentLength.bytes()));
pipeline.addLast("encoder", new HttpResponseEncoder());
if (compression) {
pipeline.addLast("encoder_compress", new HttpContentCompressor(compressionLevel));
}
pipeline.addLast("handler", requestHandler);
return pipeline;
}
};
serverBootstrap.setPipelineFactory(pipelineFactory);
serverBootstrap.setPipelineFactory(new MyChannelPipelineFactory(this));
if (tcpNoDelay != null) {
serverBootstrap.setOption("child.tcpNoDelay", tcpNoDelay);
@ -287,4 +276,36 @@ public class NettyHttpServerTransport extends AbstractLifecycleComponent<HttpSer
}
}
}
static class MyChannelPipelineFactory implements ChannelPipelineFactory {
private final NettyHttpServerTransport transport;
private final HttpRequestHandler requestHandler;
MyChannelPipelineFactory(NettyHttpServerTransport transport) {
this.transport = transport;
this.requestHandler = new HttpRequestHandler(transport);
}
@Override public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("openChannels", transport.serverOpenChannels);
pipeline.addLast("decoder", new HttpRequestDecoder(
(int) transport.maxInitialLineLength.bytes(),
(int) transport.maxHeaderSize.bytes(),
(int) transport.maxChunkSize.bytes()
));
if (transport.compression) {
pipeline.addLast("decoder_compress", new HttpContentDecompressor());
}
pipeline.addLast("aggregator", new HttpChunkAggregator((int) transport.maxContentLength.bytes()));
pipeline.addLast("encoder", new HttpResponseEncoder());
if (transport.compression) {
pipeline.addLast("encoder_compress", new HttpContentCompressor(transport.compressionLevel));
}
pipeline.addLast("handler", requestHandler);
return pipeline;
}
}
}