diff --git a/src/main/java/org/elasticsearch/http/netty/ESHttpContentDecompressor.java b/src/main/java/org/elasticsearch/http/netty/ESHttpContentDecompressor.java new file mode 100644 index 00000000000..79e845606c9 --- /dev/null +++ b/src/main/java/org/elasticsearch/http/netty/ESHttpContentDecompressor.java @@ -0,0 +1,51 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.http.netty; + +import org.elasticsearch.transport.TransportException; +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.handler.codec.embedder.DecoderEmbedder; +import org.jboss.netty.handler.codec.http.HttpContentDecompressor; +import org.jboss.netty.handler.codec.http.HttpHeaders; + +public class ESHttpContentDecompressor extends HttpContentDecompressor { + private final boolean compression; + + public ESHttpContentDecompressor(boolean compression) { + super(); + this.compression = compression; + } + + @Override + protected DecoderEmbedder newContentDecoder(String contentEncoding) throws Exception { + if (compression) { + // compression is enabled so handle the request according to the headers (compressed and uncompressed) + return super.newContentDecoder(contentEncoding); + } else { + // if compression is disabled only allow "indentity" (uncompressed) requests + if (HttpHeaders.Values.IDENTITY.equals(contentEncoding)) { + // nothing to handle here + return null; + } else { + throw new TransportException("Support for compressed content is disabled. You can enable it with http.compression=true"); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/http/netty/NettyHttpServerTransport.java b/src/main/java/org/elasticsearch/http/netty/NettyHttpServerTransport.java index 41ad895daf2..d34d97c8510 100644 --- a/src/main/java/org/elasticsearch/http/netty/NettyHttpServerTransport.java +++ b/src/main/java/org/elasticsearch/http/netty/NettyHttpServerTransport.java @@ -37,14 +37,16 @@ import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.http.*; -import org.elasticsearch.http.HttpRequest; import org.elasticsearch.monitor.jvm.JvmInfo; import org.elasticsearch.transport.BindTransportException; import org.jboss.netty.bootstrap.ServerBootstrap; import org.jboss.netty.channel.*; import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; import org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory; -import org.jboss.netty.handler.codec.http.*; +import org.jboss.netty.handler.codec.http.HttpChunkAggregator; +import org.jboss.netty.handler.codec.http.HttpContentCompressor; +import org.jboss.netty.handler.codec.http.HttpRequestDecoder; +import org.jboss.netty.handler.codec.http.HttpResponseEncoder; import org.jboss.netty.handler.timeout.ReadTimeoutException; import java.io.IOException; @@ -359,9 +361,7 @@ public class NettyHttpServerTransport extends AbstractLifecycleComponent