camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [5/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.
Date Thu, 16 Jul 2015 14:02:31 GMT
CAMEL-8976: Add maxHeadersSize option to configure the total number of bytes the http headers
must be for the server to accept.

Conflicts:
	components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpConfiguration.java


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

Branch: refs/heads/camel-2.15.x
Commit: fad6ee5a3260e089ecfc2a8a5c4864cd692b475f
Parents: d0f082e
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Jul 16 15:58:31 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Jul 16 16:05:17 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/fad6ee5a/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/fad6ee5a/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/fad6ee5a/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 28c314d..77b60ea 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
@@ -25,6 +25,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.
@@ -56,6 +57,8 @@ public class NettyHttpConfiguration extends NettyConfiguration {
     private int chunkedMaxContentLength = 1024 * 1024;
     @UriParam(defaultValue = "true")
     private boolean chunked = true;
+    @UriParam(defaultValue = "8192")
+    private int maxHeaderSize = 8192;
 
     public NettyHttpConfiguration() {
         // we need sync=true as http is request/reply by nature
@@ -176,7 +179,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/fad6ee5a/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/fad6ee5a/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");
+            }
+        };
+    }
+
+
+}


Mime
View raw message