Author: remy.maucherat(a)jboss.com
Date: 2009-06-22 10:08:51 -0400 (Mon, 22 Jun 2009)
New Revision: 1121
Modified:
trunk/java/org/apache/catalina/connector/Request.java
Log:
- Sync: support chunked POSTs.
Modified: trunk/java/org/apache/catalina/connector/Request.java
===================================================================
--- trunk/java/org/apache/catalina/connector/Request.java 2009-06-22 14:08:27 UTC (rev
1120)
+++ trunk/java/org/apache/catalina/connector/Request.java 2009-06-22 14:08:51 UTC (rev
1121)
@@ -102,6 +102,7 @@
import org.apache.catalina.util.StringParser;
import org.apache.coyote.ActionCode;
import org.apache.tomcat.util.buf.B2CConverter;
+import org.apache.tomcat.util.buf.ByteChunk;
import org.apache.tomcat.util.buf.MessageBytes;
import org.apache.tomcat.util.buf.StringCache;
import org.apache.tomcat.util.http.Cookies;
@@ -2674,7 +2675,8 @@
int maxPostSize = connector.getMaxPostSize();
if ((maxPostSize > 0) && (len > maxPostSize)) {
if (context.getLogger().isDebugEnabled()) {
- context.getLogger().debug("Post too large");
+ context.getLogger().debug(
+ sm.getString("coyoteRequest.postTooLarge"));
}
return;
}
@@ -2699,12 +2701,58 @@
return;
}
parameters.processParameters(formData, 0, len);
+ } else if ("chunked".equalsIgnoreCase(
+ coyoteRequest.getHeader("transfer-encoding"))) {
+ byte[] formData = null;
+ try {
+ formData = readChunkedPostBody();
+ } catch (IOException e) {
+ // Client disconnect
+ if (context.getLogger().isDebugEnabled()) {
+ context.getLogger().debug(
+ sm.getString("coyoteRequest.parseParameters"), e);
+ }
+ return;
+ }
+ parameters.processParameters(formData, 0, formData.length);
}
}
/**
+ * Read chunked post body.
+ */
+ protected byte[] readChunkedPostBody() throws IOException {
+ ByteChunk body = new ByteChunk();
+
+ byte[] buffer = new byte[CACHED_POST_LEN];
+
+ int len = 0;
+ while (len > -1) {
+ len = getStream().read(buffer, 0, CACHED_POST_LEN);
+ if (connector.getMaxPostSize() > 0 &&
+ (body.getLength() + len) > connector.getMaxPostSize()) {
+ // Too much data
+ throw new IllegalArgumentException(
+ sm.getString("coyoteRequest.postTooLarge"));
+ }
+ if (len > 0) {
+ body.append(buffer, 0, len);
+ }
+ }
+ if (body.getLength() < body.getBuffer().length) {
+ int length = body.getLength();
+ byte[] result = new byte[length];
+ System.arraycopy(body.getBuffer(), 0, result, 0, length);
+ return result;
+ } else {
+ return body.getBuffer();
+ }
+ }
+
+
+ /**
* Parse multipart.
*/
protected void parseMultipart() {
Show replies by date