HTTP: Support compression (gzip, deflate) when using Accept-Encoding header, closes #815.

This commit is contained in:
kimchy 2011-03-30 14:46:39 +02:00
parent eafe686013
commit 8a5dd90885
1 changed files with 15 additions and 3 deletions

View File

@ -27,9 +27,7 @@ import org.elasticsearch.common.netty.bootstrap.ServerBootstrap;
import org.elasticsearch.common.netty.channel.*;
import org.elasticsearch.common.netty.channel.socket.nio.NioServerSocketChannelFactory;
import org.elasticsearch.common.netty.channel.socket.oio.OioServerSocketChannelFactory;
import org.elasticsearch.common.netty.handler.codec.http.HttpChunkAggregator;
import org.elasticsearch.common.netty.handler.codec.http.HttpRequestDecoder;
import org.elasticsearch.common.netty.handler.codec.http.HttpResponseEncoder;
import org.elasticsearch.common.netty.handler.codec.http.*;
import org.elasticsearch.common.netty.handler.timeout.ReadTimeoutException;
import org.elasticsearch.common.netty.logging.InternalLogger;
import org.elasticsearch.common.netty.logging.InternalLoggerFactory;
@ -43,6 +41,7 @@ import org.elasticsearch.common.transport.PortsRange;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.http.*;
import org.elasticsearch.http.HttpRequest;
import org.elasticsearch.transport.BindTransportException;
import org.elasticsearch.transport.netty.NettyInternalESLoggerFactory;
@ -76,6 +75,10 @@ public class NettyHttpServerTransport extends AbstractLifecycleComponent<HttpSer
private final boolean blockingServer;
private final boolean compression;
private final int compressionLevel;
private final String port;
private final String bindHost;
@ -117,6 +120,9 @@ public class NettyHttpServerTransport extends AbstractLifecycleComponent<HttpSer
this.tcpSendBufferSize = componentSettings.getAsBytesSize("tcp_send_buffer_size", settings.getAsBytesSize(TCP_SEND_BUFFER_SIZE, TCP_DEFAULT_SEND_BUFFER_SIZE));
this.tcpReceiveBufferSize = componentSettings.getAsBytesSize("tcp_receive_buffer_size", settings.getAsBytesSize(TCP_RECEIVE_BUFFER_SIZE, TCP_DEFAULT_RECEIVE_BUFFER_SIZE));
this.compression = settings.getAsBoolean("http.compression", true);
this.compressionLevel = settings.getAsInt("http.compression_level", 6);
// validate max content length
if (maxContentLength.bytes() > Integer.MAX_VALUE) {
logger.warn("maxContentLength[" + maxContentLength + "] set to high value, resetting it to [100mb]");
@ -151,8 +157,14 @@ public class NettyHttpServerTransport extends AbstractLifecycleComponent<HttpSer
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;
}