hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r777097 - in /httpcomponents/httpcore/trunk: RELEASE_NOTES.txt httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkDecoder.java httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestChunkDecoder.java
Date Thu, 21 May 2009 12:44:51 GMT
Author: olegk
Date: Thu May 21 12:44:48 2009
New Revision: 777097

URL: http://svn.apache.org/viewvc?rev=777097&view=rev
Log:
HTTPCORE-197: Fixed bug causing the non-blocking ChunkDecoder to report some data stream as
truncated under special conditions

Modified:
    httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkDecoder.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestChunkDecoder.java

Modified: httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?rev=777097&r1=777096&r2=777097&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Thu May 21 12:44:48 2009
@@ -1,6 +1,10 @@
 Changes since 4.0
 -------------------
 
+* [HTTPCORE-197] Fixed bug causing the non-blocking ChunkDecoder to report some data stream
as 
+  truncated under special conditions.
+  Contributed by Denis Rogov <denrogov at gmail.com> and Oleg Kalnichevski <olegk
at apache.org> 
+
 * [HTTPCORE-195] Truncated chunk-coded streams can now be tolerated by catching and discarding

   TruncatedChunkException.
   Contributed by Oleg Kalnichevski <olegk at apache.org> 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkDecoder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkDecoder.java?rev=777097&r1=777096&r2=777097&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkDecoder.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/ChunkDecoder.java
Thu May 21 12:44:48 2009
@@ -200,15 +200,18 @@
                 }
                 int maxLen = this.chunkSize - this.pos;
                 int len = this.buffer.read(dst, maxLen);
-                if (maxLen > 0 && len == 0 && this.endOfStream) {
-                    this.state = COMPLETED;
-                    this.completed = true;
-                    throw new TruncatedChunkException("Truncated chunk "
-                            + "( expected size: " + this.chunkSize 
-                            + "; actual size: " + this.pos + ")");
+                if (len > 0) {
+                    this.pos += len;
+                    totalRead += len;
+                } else {
+                    if (!this.buffer.hasData() && this.endOfStream) {
+                        this.state = COMPLETED;
+                        this.completed = true;
+                        throw new TruncatedChunkException("Truncated chunk "
+                                + "( expected size: " + this.chunkSize 
+                                + "; actual size: " + this.pos + ")");
+                    }
                 }
-                this.pos += len;
-                totalRead += len;
                 
                 if (this.pos == this.chunkSize) {
                     // At the end of the chunk

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestChunkDecoder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestChunkDecoder.java?rev=777097&r1=777096&r2=777097&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestChunkDecoder.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/TestChunkDecoder.java
Thu May 21 12:44:48 2009
@@ -354,6 +354,39 @@
         assertTrue(decoder.isCompleted());
     }
 
+    public void testReadingWitSmallBuffer() throws Exception {
+        String s = "10\r\n1234567890123456\r\n" +
+                "40\r\n12345678901234561234567890123456" +
+                "12345678901234561234567890123456\r\n0\r\n";
+        ReadableByteChannel channel = new ReadableByteChannelMockup(
+                new String[] {s}, "US-ASCII"); 
+        HttpParams params = new BasicHttpParams();
+    
+        SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, params); 
+        HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
+        ChunkDecoder decoder = new ChunkDecoder(channel, inbuf, metrics);
+        
+        ByteBuffer dst = ByteBuffer.allocate(1024); 
+        ByteBuffer tmp = ByteBuffer.allocate(10); 
+
+        int bytesRead = 0;
+        while (dst.hasRemaining() && !decoder.isCompleted()) {
+            int i = decoder.read(tmp);
+            if (i > 0) {
+                bytesRead += i;
+                tmp.flip();
+                dst.put(tmp);
+                tmp.compact();
+            }
+        }
+        
+        assertEquals(80, bytesRead);
+        assertEquals("12345678901234561234567890123456" +
+        		"12345678901234561234567890123456" +
+        		"1234567890123456", convert(dst));
+        assertTrue(decoder.isCompleted());
+    }
+
     public void testEndOfStreamConditionReadingFooters() throws Exception {
         String s = "10\r\n1234567890123456\r\n" +
                 "5\r\n12345\r\n5\r\n12345\r\n0\r\n";



Mime
View raw message