camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/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:27 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.15.x adae6f5fa -> 9e2cb5fd6
  refs/heads/master 7ef6217df -> 405d55d8c


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/41b312e2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/41b312e2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/41b312e2

Branch: refs/heads/master
Commit: 41b312e2ca34672672cc9f9540a711e4f594989f
Parents: 7ef6217
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Jul 16 15:49:50 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Jul 16 15:49:50 2015 +0200

----------------------------------------------------------------------
 .../http/HttpServerInitializerFactory.java      |  4 +-
 .../HttpServerSharedInitializerFactory.java     |  3 +-
 .../netty4/http/NettyHttpConfiguration.java     | 16 ++++-
 ...ySharedHttpServerBootstrapConfiguration.java |  9 +++
 .../netty4/http/NettyHttpHeaderMaxSizeTest.java | 62 ++++++++++++++++++++
 5 files changed, 89 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/41b312e2/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/HttpServerInitializerFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/HttpServerInitializerFactory.java
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/HttpServerInitializerFactory.java
index 94fc834..1001560 100644
--- a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/HttpServerInitializerFactory.java
+++ b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/HttpServerInitializerFactory.java
@@ -86,8 +86,8 @@ public class HttpServerInitializerFactory extends ServerInitializerFactory
{
             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/41b312e2/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/HttpServerSharedInitializerFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/HttpServerSharedInitializerFactory.java
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/HttpServerSharedInitializerFactory.java
index 3ed4397..63dc729 100644
--- a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/HttpServerSharedInitializerFactory.java
+++ b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/HttpServerSharedInitializerFactory.java
@@ -82,7 +82,7 @@ public class HttpServerSharedInitializerFactory extends HttpServerInitializerFac
             pipeline.addLast("ssl", sslHandler);
         }
 
-        pipeline.addLast("decoder", new HttpRequestDecoder());
+        pipeline.addLast("decoder", new HttpRequestDecoder(409, configuration.getMaxHeadersSize(),
8192));
         if (configuration.isChunked()) {
             pipeline.addLast("aggregator", new HttpObjectAggregator(configuration.getChunkedMaxContentLength()));
         }
@@ -92,7 +92,6 @@ public class HttpServerSharedInitializerFactory extends HttpServerInitializerFac
         }
 
         pipeline.addLast("handler", channelFactory.getChannelHandler());
-        
     }
 
     private SSLContext createSSLContext() throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/41b312e2/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpConfiguration.java
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpConfiguration.java
index 468d6f8..bf0eba6 100644
--- a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpConfiguration.java
+++ b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpConfiguration.java
@@ -55,6 +55,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 +222,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 io.netty.handler.codec.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/41b312e2/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettySharedHttpServerBootstrapConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettySharedHttpServerBootstrapConfiguration.java
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettySharedHttpServerBootstrapConfiguration.java
index 0dba55d..3161036 100644
--- a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettySharedHttpServerBootstrapConfiguration.java
+++ b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/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 maxHeadersSize = 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 getMaxHeadersSize() {
+        return maxHeadersSize;
+    }
+
+    public void setMaxHeadersSize(int maxHeadersSize) {
+        this.maxHeadersSize = maxHeadersSize;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/41b312e2/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpHeaderMaxSizeTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpHeaderMaxSizeTest.java
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpHeaderMaxSizeTest.java
new file mode 100644
index 0000000..d8d76c8
--- /dev/null
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpHeaderMaxSizeTest.java
@@ -0,0 +1,62 @@
+/**
+ * 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.netty4.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(400, method.getStatusCode());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("netty4-http:http://localhost:{{port}}/myapp/mytest?maxHeaderSize=100")
+                        .transform().constant("Bye World");
+            }
+        };
+    }
+
+}


Mime
View raw message