From 5186c9412d01c46aa25fe07b6933c45069818bdb Mon Sep 17 00:00:00 2001
From: markt
Date: Tue, 23 Nov 2010 21:45:56 +0000
Subject: [PATCH] Move configuration of trailer header size limit to the
connector
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1038351 13f79535-47bb-0310-9956-ffa450edef68
---
java/org/apache/coyote/Constants.java | 11 +----------
.../apache/coyote/http11/AbstractHttp11Processor.java | 4 ++--
.../org/apache/coyote/http11/AbstractHttp11Protocol.java | 10 ++++++++++
java/org/apache/coyote/http11/Http11AprProcessor.java | 5 +++--
java/org/apache/coyote/http11/Http11AprProtocol.java | 3 ++-
java/org/apache/coyote/http11/Http11NioProcessor.java | 5 +++--
java/org/apache/coyote/http11/Http11NioProtocol.java | 4 ++--
java/org/apache/coyote/http11/Http11Processor.java | 5 +++--
java/org/apache/coyote/http11/Http11Protocol.java | 5 +++--
.../apache/coyote/http11/filters/ChunkedInputFilter.java | 16 +++++-----------
.../coyote/http11/filters/TestChunkedInputFilter.java | 9 +++------
webapps/docs/config/http.xml | 7 +++++++
webapps/docs/config/systemprops.xml | 7 -------
13 files changed, 44 insertions(+), 47 deletions(-)
diff --git a/java/org/apache/coyote/Constants.java b/java/org/apache/coyote/Constants.java
index a610e3bc2..2d87e06d5 100644
--- a/java/org/apache/coyote/Constants.java
+++ b/java/org/apache/coyote/Constants.java
@@ -67,14 +67,5 @@ public final class Constants {
public static final boolean USE_CUSTOM_STATUS_MSG_IN_HEADER =
Boolean.valueOf(System.getProperty(
"org.apache.coyote.USE_CUSTOM_STATUS_MSG_IN_HEADER",
- "false")).booleanValue();
-
- /**
- * Limit on the total length of the trailer headers in
- * a chunked HTTP request.
- */
- public static final int MAX_TRAILER_SIZE =
- Integer.parseInt(System.getProperty(
- "org.apache.coyote.MAX_TRAILER_SIZE",
- "8192"));
+ "false")).booleanValue();
}
diff --git a/java/org/apache/coyote/http11/AbstractHttp11Processor.java b/java/org/apache/coyote/http11/AbstractHttp11Processor.java
index 22be36519..34598a930 100644
--- a/java/org/apache/coyote/http11/AbstractHttp11Processor.java
+++ b/java/org/apache/coyote/http11/AbstractHttp11Processor.java
@@ -771,13 +771,13 @@ public abstract class AbstractHttp11Processor implements ActionHook, Processor {
/**
* Initialize standard input and output filters.
*/
- protected void initializeFilters() {
+ protected void initializeFilters(int maxTrailerSize) {
// Create and add the identity filters.
getInputBuffer().addFilter(new IdentityInputFilter());
getOutputBuffer().addFilter(new IdentityOutputFilter());
// Create and add the chunked filters.
- getInputBuffer().addFilter(new ChunkedInputFilter());
+ getInputBuffer().addFilter(new ChunkedInputFilter(maxTrailerSize));
getOutputBuffer().addFilter(new ChunkedOutputFilter());
// Create and add the void filters.
diff --git a/java/org/apache/coyote/http11/AbstractHttp11Protocol.java b/java/org/apache/coyote/http11/AbstractHttp11Protocol.java
index 1cd32a99f..717e4d337 100644
--- a/java/org/apache/coyote/http11/AbstractHttp11Protocol.java
+++ b/java/org/apache/coyote/http11/AbstractHttp11Protocol.java
@@ -332,6 +332,16 @@ public abstract class AbstractHttp11Protocol implements ProtocolHandler, MBeanRe
public void setServer( String server ) { this.server = server; }
public String getServer() { return server; }
+ // HTTP
+ /**
+ * Maximum size of trailing headers in bytes
+ */
+ private int maxTrailerSize = 8192;
+ public int getMaxTrailerSize() { return maxTrailerSize; }
+ public void setMaxTrailerSize(int maxTrailerSize) {
+ this.maxTrailerSize = maxTrailerSize;
+ }
+
@Override
public Executor getExecutor() { return endpoint.getExecutor(); }
public void setExecutor(Executor executor) { endpoint.setExecutor(executor); }
diff --git a/java/org/apache/coyote/http11/Http11AprProcessor.java b/java/org/apache/coyote/http11/Http11AprProcessor.java
index a5b374bd8..c13c46ed9 100644
--- a/java/org/apache/coyote/http11/Http11AprProcessor.java
+++ b/java/org/apache/coyote/http11/Http11AprProcessor.java
@@ -66,7 +66,8 @@ public class Http11AprProcessor extends AbstractHttp11Processor {
// ----------------------------------------------------------- Constructors
- public Http11AprProcessor(int headerBufferSize, AprEndpoint endpoint) {
+ public Http11AprProcessor(int headerBufferSize, AprEndpoint endpoint,
+ int maxTrailerSize) {
this.endpoint = endpoint;
@@ -82,7 +83,7 @@ public class Http11AprProcessor extends AbstractHttp11Processor {
ssl = endpoint.isSSLEnabled();
- initializeFilters();
+ initializeFilters(maxTrailerSize);
// Cause loading of HexUtils
HexUtils.load();
diff --git a/java/org/apache/coyote/http11/Http11AprProtocol.java b/java/org/apache/coyote/http11/Http11AprProtocol.java
index 05edd52f0..13756f1b8 100644
--- a/java/org/apache/coyote/http11/Http11AprProtocol.java
+++ b/java/org/apache/coyote/http11/Http11AprProtocol.java
@@ -433,7 +433,8 @@ public class Http11AprProtocol extends AbstractHttp11Protocol {
protected Http11AprProcessor createProcessor() {
Http11AprProcessor processor = new Http11AprProcessor(
- proto.getMaxHttpHeaderSize(), (AprEndpoint)proto.endpoint);
+ proto.getMaxHttpHeaderSize(), (AprEndpoint)proto.endpoint,
+ proto.getMaxTrailerSize());
processor.setAdapter(proto.adapter);
processor.setMaxKeepAliveRequests(proto.getMaxKeepAliveRequests());
processor.setTimeout(proto.timeout);
diff --git a/java/org/apache/coyote/http11/Http11NioProcessor.java b/java/org/apache/coyote/http11/Http11NioProcessor.java
index a48ecf243..3d5ff2ce8 100644
--- a/java/org/apache/coyote/http11/Http11NioProcessor.java
+++ b/java/org/apache/coyote/http11/Http11NioProcessor.java
@@ -68,7 +68,8 @@ public class Http11NioProcessor extends AbstractHttp11Processor {
// ----------------------------------------------------------- Constructors
- public Http11NioProcessor(int maxHttpHeaderSize, NioEndpoint endpoint) {
+ public Http11NioProcessor(int maxHttpHeaderSize, NioEndpoint endpoint,
+ int maxTrailerSize) {
this.endpoint = endpoint;
@@ -84,7 +85,7 @@ public class Http11NioProcessor extends AbstractHttp11Processor {
ssl = endpoint.isSSLEnabled();
- initializeFilters();
+ initializeFilters(maxTrailerSize);
// Cause loading of HexUtils
HexUtils.load();
diff --git a/java/org/apache/coyote/http11/Http11NioProtocol.java b/java/org/apache/coyote/http11/Http11NioProtocol.java
index 2d36591fe..c92f0f658 100644
--- a/java/org/apache/coyote/http11/Http11NioProtocol.java
+++ b/java/org/apache/coyote/http11/Http11NioProtocol.java
@@ -433,8 +433,8 @@ public class Http11NioProtocol extends AbstractHttp11JsseProtocol {
public Http11NioProcessor createProcessor() {
Http11NioProcessor processor = new Http11NioProcessor(
- proto.getMaxHttpHeaderSize(),
- (NioEndpoint)proto.endpoint);
+ proto.getMaxHttpHeaderSize(), (NioEndpoint)proto.endpoint,
+ proto.getMaxTrailerSize());
processor.setAdapter(proto.adapter);
processor.setMaxKeepAliveRequests(proto.getMaxKeepAliveRequests());
processor.setTimeout(proto.getTimeout());
diff --git a/java/org/apache/coyote/http11/Http11Processor.java b/java/org/apache/coyote/http11/Http11Processor.java
index dd223a84d..59f790923 100644
--- a/java/org/apache/coyote/http11/Http11Processor.java
+++ b/java/org/apache/coyote/http11/Http11Processor.java
@@ -61,7 +61,8 @@ public class Http11Processor extends AbstractHttp11Processor {
// ------------------------------------------------------------ Constructor
- public Http11Processor(int headerBufferSize, JIoEndpoint endpoint) {
+ public Http11Processor(int headerBufferSize, JIoEndpoint endpoint,
+ int maxTrailerSize) {
this.endpoint = endpoint;
@@ -75,7 +76,7 @@ public class Http11Processor extends AbstractHttp11Processor {
response.setOutputBuffer(outputBuffer);
request.setResponse(response);
- initializeFilters();
+ initializeFilters(maxTrailerSize);
// Cause loading of HexUtils
HexUtils.load();
diff --git a/java/org/apache/coyote/http11/Http11Protocol.java b/java/org/apache/coyote/http11/Http11Protocol.java
index 7cd7b26d4..e4ed1e111 100644
--- a/java/org/apache/coyote/http11/Http11Protocol.java
+++ b/java/org/apache/coyote/http11/Http11Protocol.java
@@ -293,8 +293,9 @@ public class Http11Protocol extends AbstractHttp11JsseProtocol {
}
protected Http11Processor createProcessor() {
- Http11Processor processor =
- new Http11Processor(proto.getMaxHttpHeaderSize(), (JIoEndpoint)proto.endpoint);
+ Http11Processor processor = new Http11Processor(
+ proto.getMaxHttpHeaderSize(), (JIoEndpoint)proto.endpoint,
+ proto.getMaxTrailerSize());
processor.setAdapter(proto.adapter);
processor.setMaxKeepAliveRequests(proto.getMaxKeepAliveRequests());
processor.setKeepAliveTimeout(proto.getKeepAliveTimeout());
diff --git a/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java b/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java
index ab91acf06..a48ae3555 100644
--- a/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java
+++ b/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java
@@ -102,15 +102,7 @@ public class ChunkedInputFilter implements InputFilter {
/**
* Byte chunk used to store trailing headers.
*/
- protected ByteChunk trailingHeaders;
-
- {
- trailingHeaders = new ByteChunk();
- if (org.apache.coyote.Constants.MAX_TRAILER_SIZE > 0) {
- trailingHeaders.setLimit(org.apache.coyote.Constants.MAX_TRAILER_SIZE);
- }
- }
-
+ protected ByteChunk trailingHeaders = new ByteChunk();
/**
* Flag set to true if the next call to doRead() must parse a CRLF pair
@@ -124,8 +116,10 @@ public class ChunkedInputFilter implements InputFilter {
*/
private Request request;
- // ------------------------------------------------------------- Properties
-
+ // ----------------------------------------------------------- Constructors
+ public ChunkedInputFilter(int maxTrailerSize) {
+ this.trailingHeaders.setLimit(maxTrailerSize);
+ }
// ---------------------------------------------------- InputBuffer Methods
diff --git a/test/org/apache/coyote/http11/filters/TestChunkedInputFilter.java b/test/org/apache/coyote/http11/filters/TestChunkedInputFilter.java
index 265d7f54a..f85cc3881 100644
--- a/test/org/apache/coyote/http11/filters/TestChunkedInputFilter.java
+++ b/test/org/apache/coyote/http11/filters/TestChunkedInputFilter.java
@@ -82,13 +82,10 @@ public class TestChunkedInputFilter extends TomcatBaseTest {
Tomcat.addServlet(ctx, "servlet", new EchoHeaderServlet());
ctx.addServletMapping("/", "servlet");
+ // Limit the size of the trailing header
+ tomcat.getConnector().setProperty("maxTrailerSize", "10");
tomcat.start();
- StringBuilder longText = new StringBuilder("Test1234567890");
- while (longText.length() <= 8192) {
- longText.append(longText.toString());
- }
-
String[] request = new String[]{
"POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
"Host: any" + SimpleHttpClient.CRLF +
@@ -102,7 +99,7 @@ public class TestChunkedInputFilter extends TomcatBaseTest {
"4" + SimpleHttpClient.CRLF +
"&b=1" + SimpleHttpClient.CRLF +
"0" + SimpleHttpClient.CRLF +
- "x-trailer: Test" + longText + SimpleHttpClient.CRLF +
+ "x-trailer: Test" + SimpleHttpClient.CRLF +
SimpleHttpClient.CRLF };
TrailerClient client = new TrailerClient();
diff --git a/webapps/docs/config/http.xml b/webapps/docs/config/http.xml
index 3454fdf90..915c32ae4 100644
--- a/webapps/docs/config/http.xml
+++ b/webapps/docs/config/http.xml
@@ -335,6 +335,13 @@
execute tasks using the executor rather than an internal thread pool.
+
+ Limits the total length of trailing headers in the last chunk of
+ a chunked HTTP request. If the value is -1, no limit will be
+ imposed. If not specified, the default value of 8192 will be
+ used.
+
+
The minimum number of threads always kept running. If not specified,
the default of 10 is used.
diff --git a/webapps/docs/config/systemprops.xml b/webapps/docs/config/systemprops.xml
index 56c8c1cb6..f2dc78eca 100644
--- a/webapps/docs/config/systemprops.xml
+++ b/webapps/docs/config/systemprops.xml
@@ -474,13 +474,6 @@
If not specified, the default value of false will be used.
-
- Limits the total length of trailing headers in the last chunk of
- a chunked HTTP request.
- If the value is -1, no limit will be imposed.
- If not specified, the default value of 8192 will be used.
-
-
If this is false it will override the
useNaming attribute for all
--
2.11.0