Skip to content

Commit 5ac51ee

Browse files
committed
HTTP: Rest API should support receiving HTTP. Closes elastic#8.
1 parent 14f2445 commit 5ac51ee

File tree

2 files changed

+13
-24
lines changed

2 files changed

+13
-24
lines changed

modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/NettyHttpServerTransport.java

+13
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.elasticsearch.http.*;
2525
import org.elasticsearch.threadpool.ThreadPool;
2626
import org.elasticsearch.transport.BindTransportException;
27+
import org.elasticsearch.util.SizeUnit;
2728
import org.elasticsearch.util.SizeValue;
2829
import org.elasticsearch.util.TimeValue;
2930
import org.elasticsearch.util.component.AbstractComponent;
@@ -36,6 +37,7 @@
3637
import org.jboss.netty.bootstrap.ServerBootstrap;
3738
import org.jboss.netty.channel.*;
3839
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
40+
import org.jboss.netty.handler.codec.http.HttpChunkAggregator;
3941
import org.jboss.netty.handler.codec.http.HttpRequestDecoder;
4042
import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
4143
import org.jboss.netty.handler.timeout.ReadTimeoutException;
@@ -73,6 +75,8 @@ public class NettyHttpServerTransport extends AbstractComponent implements HttpS
7375

7476
private final ThreadPool threadPool;
7577

78+
private final SizeValue maxContentLength;
79+
7680
private final int workerCount;
7781

7882
private final String port;
@@ -108,6 +112,7 @@ public class NettyHttpServerTransport extends AbstractComponent implements HttpS
108112
@Inject public NettyHttpServerTransport(Settings settings, ThreadPool threadPool) {
109113
super(settings);
110114
this.threadPool = threadPool;
115+
SizeValue maxContentLength = componentSettings.getAsSize("maxContentLength", new SizeValue(100, SizeUnit.MB));
111116
this.workerCount = componentSettings.getAsInt("workerCount", Runtime.getRuntime().availableProcessors());
112117
this.port = componentSettings.get("port", "9200-9300");
113118
this.bindHost = componentSettings.get("bindHost");
@@ -123,6 +128,13 @@ public class NettyHttpServerTransport extends AbstractComponent implements HttpS
123128
if ((httpKeepAliveTickDuration.millis() * 10) > httpKeepAlive.millis()) {
124129
logger.warn("Suspicious keep alive settings, httpKeepAlive set to [{}], while httpKeepAliveTickDuration is set to [{}]", httpKeepAlive, httpKeepAliveTickDuration);
125130
}
131+
132+
// validate max content length
133+
if (maxContentLength.bytes() > Integer.MAX_VALUE) {
134+
logger.warn("maxContentLength[" + maxContentLength + "] set to high value, resetting it to [100mb]");
135+
maxContentLength = new SizeValue(100, SizeUnit.MB);
136+
}
137+
this.maxContentLength = maxContentLength;
126138
}
127139

128140
@Override public Lifecycle.State lifecycleState() {
@@ -154,6 +166,7 @@ public void httpServerAdapter(HttpServerAdapter httpServerAdapter) {
154166
pipeline.addLast("openChannels", serverOpenChannels);
155167
pipeline.addLast("keepAliveTimeout", new ReadTimeoutHandler(keepAliveTimer, httpKeepAlive.millis(), TimeUnit.MILLISECONDS));
156168
pipeline.addLast("decoder", new HttpRequestDecoder());
169+
pipeline.addLast("aggregator", new HttpChunkAggregator((int) maxContentLength.bytes()));
157170
pipeline.addLast("encoder", new HttpResponseEncoder());
158171
pipeline.addLast("handler", requestHandler);
159172
return pipeline;

modules/elasticsearch/src/main/java/org/elasticsearch/http/netty/SimpleNettyHttpTransportTests.java

-24
This file was deleted.

0 commit comments

Comments
 (0)