You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2013/05/24 16:08:26 UTC
svn commit: r1486060 - in /tomcat/trunk/java/org/apache: catalina/connector/
coyote/ coyote/http11/ coyote/http11/filters/
Author: markt
Date: Fri May 24 14:08:25 2013
New Revision: 1486060
URL: http://svn.apache.org/r1486060
Log:
Implement new isFinished() method that identifies when a request body has been fully read. Required since available()==0 != isFinished()
Modified:
tomcat/trunk/java/org/apache/catalina/connector/Request.java
tomcat/trunk/java/org/apache/coyote/ActionCode.java
tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java
tomcat/trunk/java/org/apache/coyote/http11/AbstractInputBuffer.java
tomcat/trunk/java/org/apache/coyote/http11/InputFilter.java
tomcat/trunk/java/org/apache/coyote/http11/filters/BufferedInputFilter.java
tomcat/trunk/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java
tomcat/trunk/java/org/apache/coyote/http11/filters/IdentityInputFilter.java
tomcat/trunk/java/org/apache/coyote/http11/filters/SavedRequestInputFilter.java
tomcat/trunk/java/org/apache/coyote/http11/filters/VoidInputFilter.java
Modified: tomcat/trunk/java/org/apache/catalina/connector/Request.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/Request.java?rev=1486060&r1=1486059&r2=1486060&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/Request.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/Request.java Fri May 24 14:08:25 2013
@@ -2443,6 +2443,18 @@ public class Request
return (inputBuffer.available() > 0);
}
+
+ /**
+ * Return true if an attempt has been made to read the request body and all
+ * of the request body has been read
+ */
+ public boolean isFinished() {
+ AtomicBoolean result = new AtomicBoolean(false);
+ coyoteRequest.action(ActionCode.REQUEST_BODY_FULLY_READ, result);
+ return result.get();
+ }
+
+
/**
* Disable swallowing of remaining input if configured
*/
Modified: tomcat/trunk/java/org/apache/coyote/ActionCode.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/ActionCode.java?rev=1486060&r1=1486059&r2=1486060&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/ActionCode.java (original)
+++ tomcat/trunk/java/org/apache/coyote/ActionCode.java Fri May 24 14:08:25 2013
@@ -210,5 +210,10 @@ public enum ActionCode {
*Indicator that the Servlet is interested
*in being notified when it can write data
*/
- NB_WRITE_INTEREST
+ NB_WRITE_INTEREST,
+
+ /**
+ * Indicates if the request body has been fully read.
+ */
+ REQUEST_BODY_FULLY_READ
}
Modified: tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java?rev=1486060&r1=1486059&r2=1486060&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/AbstractHttp11Processor.java Fri May 24 14:08:25 2013
@@ -822,6 +822,9 @@ public abstract class AbstractHttp11Proc
httpUpgradeHandler = (HttpUpgradeHandler) param;
// Stop further HTTP output
getOutputBuffer().finished = true;
+ } else if (actionCode == ActionCode.REQUEST_BODY_FULLY_READ) {
+ AtomicBoolean result = (AtomicBoolean) param;
+ result.set(getInputBuffer().isFinished());
} else {
actionInternal(actionCode, param);
}
Modified: tomcat/trunk/java/org/apache/coyote/http11/AbstractInputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/AbstractInputBuffer.java?rev=1486060&r1=1486059&r2=1486060&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/AbstractInputBuffer.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/AbstractInputBuffer.java Fri May 24 14:08:25 2013
@@ -344,6 +344,37 @@ public abstract class AbstractInputBuffe
}
+ /**
+ * Has all of the request body been read? There are subtle differences
+ * between this and available() > 0 primarily because of having to handle
+ * faking non-blocking reads with the blocking IO connector.
+ */
+ public boolean isFinished() {
+ if (lastValid > pos) {
+ // Data to read in the buffer so not finished
+ return false;
+ }
+
+ /*
+ * Don't use fill(false) here because in the following circumstances
+ * BIO will block - possibly indefinitely
+ * - client is using keep-alive and connection is still open
+ * - client has sent the complete request
+ * - client has not sent any of the next request (i.e. no pipelining)
+ * - application has read the complete request
+ */
+
+ // Check the InputFilters
+
+ if (lastActiveFilter >= 0) {
+ return activeFilters[lastActiveFilter].isFinished();
+ } else {
+ // No filters. Assume request is not finished. EOF will signal end of
+ // request.
+ return false;
+ }
+ }
+
// ---------------------------------------------------- InputBuffer Methods
/**
Modified: tomcat/trunk/java/org/apache/coyote/http11/InputFilter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/InputFilter.java?rev=1486060&r1=1486059&r2=1486060&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/InputFilter.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/InputFilter.java Fri May 24 14:08:25 2013
@@ -85,4 +85,8 @@ public interface InputFilter extends Inp
public int available();
+ /**
+ * Has the request body been read fully?
+ */
+ public boolean isFinished();
}
Modified: tomcat/trunk/java/org/apache/coyote/http11/filters/BufferedInputFilter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/filters/BufferedInputFilter.java?rev=1486060&r1=1486059&r2=1486060&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/filters/BufferedInputFilter.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/filters/BufferedInputFilter.java Fri May 24 14:08:25 2013
@@ -138,4 +138,9 @@ public class BufferedInputFilter impleme
return buffered.getLength();
}
+
+ @Override
+ public boolean isFinished() {
+ return hasRead || buffered.getLength() <= 0;
+ }
}
Modified: tomcat/trunk/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java?rev=1486060&r1=1486059&r2=1486060&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java Fri May 24 14:08:25 2013
@@ -537,4 +537,9 @@ public class ChunkedInputFilter implemen
return true;
}
+
+ @Override
+ public boolean isFinished() {
+ return endChunk;
+ }
}
Modified: tomcat/trunk/java/org/apache/coyote/http11/filters/IdentityInputFilter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/filters/IdentityInputFilter.java?rev=1486060&r1=1486059&r2=1486060&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/filters/IdentityInputFilter.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/filters/IdentityInputFilter.java Fri May 24 14:08:25 2013
@@ -195,4 +195,10 @@ public class IdentityInputFilter impleme
}
+ @Override
+ public boolean isFinished() {
+ // Only finished if a content length is defined and there is no data
+ // remaining
+ return contentLength > -1 && remaining == 0;
+ }
}
Modified: tomcat/trunk/java/org/apache/coyote/http11/filters/SavedRequestInputFilter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/filters/SavedRequestInputFilter.java?rev=1486060&r1=1486059&r2=1486060&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/filters/SavedRequestInputFilter.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/filters/SavedRequestInputFilter.java Fri May 24 14:08:25 2013
@@ -115,4 +115,8 @@ public class SavedRequestInputFilter imp
return 0;
}
+ @Override
+ public boolean isFinished() {
+ return input.getOffset() >= input.getEnd();
+ }
}
Modified: tomcat/trunk/java/org/apache/coyote/http11/filters/VoidInputFilter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/filters/VoidInputFilter.java?rev=1486060&r1=1486059&r2=1486060&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/filters/VoidInputFilter.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/filters/VoidInputFilter.java Fri May 24 14:08:25 2013
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.coyote.http11.filters;
import java.io.IOException;
@@ -36,14 +35,12 @@ public class VoidInputFilter implements
// -------------------------------------------------------------- Constants
-
protected static final String ENCODING_NAME = "void";
protected static final ByteChunk ENCODING = new ByteChunk();
// ----------------------------------------------------- Static Initializer
-
static {
ENCODING.setBytes(ENCODING_NAME.getBytes(B2CConverter.ISO_8859_1), 0,
ENCODING_NAME.length());
@@ -52,9 +49,11 @@ public class VoidInputFilter implements
// ----------------------------------------------------- Instance Variables
+ // Tracks if an attempt has been made to read data
+ private boolean read = false;
- // --------------------------------------------------- OutputBuffer Methods
+ // ---------------------------------------------------- InputBuffer Methods
/**
* Write some bytes.
@@ -62,16 +61,13 @@ public class VoidInputFilter implements
* @return number of bytes written by the filter
*/
@Override
- public int doRead(ByteChunk chunk, Request req)
- throws IOException {
-
+ public int doRead(ByteChunk chunk, Request req) throws IOException {
+ read = true;
return -1;
-
}
- // --------------------------------------------------- OutputFilter Methods
-
+ // ---------------------------------------------------- InputFilter Methods
/**
* Set the associated request.
@@ -96,7 +92,7 @@ public class VoidInputFilter implements
*/
@Override
public void recycle() {
- // NOOP: Nothing to recycle
+ read = false;
}
@@ -120,18 +116,19 @@ public class VoidInputFilter implements
* Note: It is recommended that extra bytes be swallowed by the filter.
*/
@Override
- public long end()
- throws IOException {
+ public long end() throws IOException {
return 0;
}
- /**
- * Amount of bytes still available in a buffer.
- */
@Override
public int available() {
return 0;
}
+
+ @Override
+ public boolean isFinished() {
+ return read;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org