You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/07/16 16:02:28 UTC

[2/6] camel git commit: CAMEL-8976: Add maxHeadersSize option to configure the total number of bytes the http headers must be for the server to accept.

CAMEL-8976: Add maxHeadersSize option to configure the total number of bytes the http headers must be for the server to accept.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0ca892f1
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0ca892f1
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0ca892f1

Branch: refs/heads/master
Commit: 0ca892f1eea3ca0d5829179363990745db5a9d29
Parents: 41b312e
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jul 16 15:58:31 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jul 16 15:58:31 2015 +0200

----------------------------------------------------------------------
 .../netty/http/HttpServerPipelineFactory.java   |  4 +-
 .../http/HttpServerSharedPipelineFactory.java   |  2 +-
 .../netty/http/NettyHttpConfiguration.java      | 17 +++++-
 ...ySharedHttpServerBootstrapConfiguration.java |  9 +++
 .../netty/http/NettyHttpHeaderMaxSizeTest.java  | 63 ++++++++++++++++++++
 5 files changed, 91 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/0ca892f1/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerPipelineFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerPipelineFactory.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerPipelineFactory.java
index 84a4eeb..56095e1 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerPipelineFactory.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerPipelineFactory.java
@@ -85,8 +85,8 @@ public class HttpServerPipelineFactory extends ServerPipelineFactory {
             LOG.debug("Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
             pipeline.addLast("ssl", sslHandler);
         }
-        
-        pipeline.addLast("decoder", new HttpRequestDecoder());
+
+        pipeline.addLast("decoder", new HttpRequestDecoder(4096, configuration.getMaxHeaderSize(), 8192));
         List<ChannelHandler> decoders = consumer.getConfiguration().getDecoders();
         for (int x = 0; x < decoders.size(); x++) {
             ChannelHandler decoder = decoders.get(x);

http://git-wip-us.apache.org/repos/asf/camel/blob/0ca892f1/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerSharedPipelineFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerSharedPipelineFactory.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerSharedPipelineFactory.java
index f9b4cd0..22eae48 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerSharedPipelineFactory.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerSharedPipelineFactory.java
@@ -82,7 +82,7 @@ public class HttpServerSharedPipelineFactory extends HttpServerPipelineFactory {
             pipeline.addLast("ssl", sslHandler);
         }
 
-        pipeline.addLast("decoder", new HttpRequestDecoder());
+        pipeline.addLast("decoder", new HttpRequestDecoder(4096, configuration.getMaxHeaderSize(), 8192));
         if (configuration.isChunked()) {
             pipeline.addLast("aggregator", new HttpChunkAggregator(configuration.getChunkedMaxContentLength()));
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/0ca892f1/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpConfiguration.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpConfiguration.java
index 51c907c..7847d96 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpConfiguration.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpConfiguration.java
@@ -26,6 +26,7 @@ import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriParams;
 import org.apache.camel.spi.UriPath;
 import org.jboss.netty.channel.ChannelHandler;
+import org.jboss.netty.handler.codec.frame.TooLongFrameException;
 
 /**
  * Extended configuration for using HTTP with Netty.
@@ -55,6 +56,8 @@ public class NettyHttpConfiguration extends NettyConfiguration {
     private boolean send503whenSuspended = true;
     @UriParam(defaultValue = "" + 1024 * 1024)
     private int chunkedMaxContentLength = 1024 * 1024;
+    @UriParam(defaultValue = "8192")
+    private int maxHeaderSize = 8192;
 
     public NettyHttpConfiguration() {
         // we need sync=true as http is request/reply by nature
@@ -220,7 +223,19 @@ public class NettyHttpConfiguration extends NettyConfiguration {
     public void setChunkedMaxContentLength(int chunkedMaxContentLength) {
         this.chunkedMaxContentLength = chunkedMaxContentLength;
     }
-    
+
+    public int getMaxHeaderSize() {
+        return maxHeaderSize;
+    }
+
+    /**
+     * The maximum length of all headers.
+     * If the sum of the length of each header exceeds this value, a {@link TooLongFrameException} will be raised.
+     */
+    public void setMaxHeaderSize(int maxHeaderSize) {
+        this.maxHeaderSize = maxHeaderSize;
+    }
+
     // Don't support allowDefaultCodec
     public boolean isAllowDefaultCodec() {
         return false;

http://git-wip-us.apache.org/repos/asf/camel/blob/0ca892f1/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettySharedHttpServerBootstrapConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettySharedHttpServerBootstrapConfiguration.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettySharedHttpServerBootstrapConfiguration.java
index cf785c4..809d82c 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettySharedHttpServerBootstrapConfiguration.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettySharedHttpServerBootstrapConfiguration.java
@@ -23,6 +23,7 @@ public class NettySharedHttpServerBootstrapConfiguration extends NettyServerBoot
     private int chunkedMaxContentLength = 1024 * 1024;
     private boolean chunked = true;
     private boolean compression;
+    private int maxHeaderSize = 8192;
 
     public boolean isChunked() {
         return chunked;
@@ -47,4 +48,12 @@ public class NettySharedHttpServerBootstrapConfiguration extends NettyServerBoot
     public void setCompression(boolean compression) {
         this.compression = compression;
     }
+
+    public int getMaxHeaderSize() {
+        return maxHeaderSize;
+    }
+
+    public void setMaxHeaderSize(int maxHeaderSize) {
+        this.maxHeaderSize = maxHeaderSize;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/0ca892f1/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpHeaderMaxSizeTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpHeaderMaxSizeTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpHeaderMaxSizeTest.java
new file mode 100644
index 0000000..6b897a6
--- /dev/null
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpHeaderMaxSizeTest.java
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.apache.camel.component.netty.http;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.junit.Test;
+
+public class NettyHttpHeaderMaxSizeTest extends BaseNettyTest {
+
+    @Test
+    public void testHttpHeaderMaxSizeOk() throws Exception {
+        HttpClient client = new HttpClient();
+        HttpMethod method = new PostMethod("http://localhost:" + getPort() + "/myapp/mytest");
+
+        method.setRequestHeader("name", "you");
+
+        client.executeMethod(method);
+
+        assertEquals(200, method.getStatusCode());
+        assertEquals("Bye World", method.getResponseBodyAsString());
+    }
+
+    @Test
+    public void testHttpHeaderMaxSizeFail() throws Exception {
+        HttpClient client = new HttpClient();
+        HttpMethod method = new PostMethod("http://localhost:" + getPort() + "/myapp/mytest");
+
+        method.setRequestHeader("name", "12345678901234567890123456789012345678901234567890123456789012345678901234567890");
+
+        client.executeMethod(method);
+
+        assertEquals(404, method.getStatusCode());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("netty-http:http://localhost:{{port}}/myapp/mytest?maxHeaderSize=100")
+                        .transform().constant("Bye World");
+            }
+        };
+    }
+
+
+}