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();
}
/**
* 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.
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); }
// ----------------------------------------------------------- Constructors
- public Http11AprProcessor(int headerBufferSize, AprEndpoint endpoint) {
+ public Http11AprProcessor(int headerBufferSize, AprEndpoint endpoint,
+ int maxTrailerSize) {
this.endpoint = endpoint;
ssl = endpoint.isSSLEnabled();
- initializeFilters();
+ initializeFilters(maxTrailerSize);
// Cause loading of HexUtils
HexUtils.load();
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);
// ----------------------------------------------------------- Constructors
- public Http11NioProcessor(int maxHttpHeaderSize, NioEndpoint endpoint) {
+ public Http11NioProcessor(int maxHttpHeaderSize, NioEndpoint endpoint,
+ int maxTrailerSize) {
this.endpoint = endpoint;
ssl = endpoint.isSSLEnabled();
- initializeFilters();
+ initializeFilters(maxTrailerSize);
// Cause loading of HexUtils
HexUtils.load();
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());
// ------------------------------------------------------------ Constructor
- public Http11Processor(int headerBufferSize, JIoEndpoint endpoint) {
+ public Http11Processor(int headerBufferSize, JIoEndpoint endpoint,
+ int maxTrailerSize) {
this.endpoint = endpoint;
response.setOutputBuffer(outputBuffer);
request.setResponse(response);
- initializeFilters();
+ initializeFilters(maxTrailerSize);
// Cause loading of HexUtils
HexUtils.load();
}
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());
/**
* 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
*/
private Request request;
- // ------------------------------------------------------------- Properties
-
+ // ----------------------------------------------------------- Constructors
+ public ChunkedInputFilter(int maxTrailerSize) {
+ this.trailingHeaders.setLimit(maxTrailerSize);
+ }
// ---------------------------------------------------- InputBuffer Methods
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 +
"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();
execute tasks using the executor rather than an internal thread pool.</p>
</attribute>
+ <attribute name="maxTrailerSize">
+ <p>Limits the total length of trailing headers in the last chunk of
+ a chunked HTTP request. If the value is <code>-1</code>, no limit will be
+ imposed. If not specified, the default value of <code>8192</code> will be
+ used.</p>
+ </attribute>
+
<attribute name="minSpareThreads" required="false">
<p>The minimum number of threads always kept running. If not specified,
the default of <code>10</code> is used.</p>
<p>If not specified, the default value of <code>false</code> will be used.</p>
</property>
- <property name="org.apache.coyote.MAX_TRAILER_SIZE">
- <p>Limits the total length of trailing headers in the last chunk of
- a chunked HTTP request.
- If the value is <code>-1</code>, no limit will be imposed.</p>
- <p>If not specified, the default value of <code>8192</code> will be used.</p>
- </property>
-
<property name="catalina.useNaming">
<p>If this is <code>false</code> it will override the
<code>useNaming</code> attribute for all <a href="context.html">