remm 01/06/19 20:15:51
Modified: httpclient/src/java/org/apache/commons/httpclient
ResponseInputStream.java
Log:
- If an error occurs when parsing the chunk length, don't call close(), and directly
close the stream.
- Don't attempt to read bytes when closing the stream if none are available.
This should fix issues when doing a HEAD request, which contain bogus
content-length
and content-encoding headers.
Many thanks to Eylon Stroh <estroh at nuance.com> for the bug report
Revision Changes Path
1.4 +15 -6
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ResponseInputStream.java
Index: ResponseInputStream.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ResponseInputStream.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ResponseInputStream.java 2001/05/01 16:17:33 1.3
+++ ResponseInputStream.java 2001/06/20 03:15:47 1.4
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ResponseInputStream.java,v
1.3 2001/05/01 16:17:33 morgand Exp $
- * $Revision: 1.3 $
- * $Date: 2001/05/01 16:17:33 $
+ * $Header:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ResponseInputStream.java,v
1.4 2001/06/20 03:15:47 remm Exp $
+ * $Revision: 1.4 $
+ * $Date: 2001/06/20 03:15:47 $
*
* ====================================================================
*
@@ -74,7 +74,7 @@
* Socket input stream wrapper.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a>
- * @version $Revision: 1.3 $ $Date: 2001/05/01 16:17:33 $
+ * @version $Revision: 1.4 $ $Date: 2001/06/20 03:15:47 $
*/
public class ResponseInputStream
@@ -209,6 +209,14 @@
if (closed)
throw new IOException("Stream is already closed");
*/
+
+ int available = stream.available();
+ // Don't do anything if no bytes are available
+ if (available <= 0) {
+ closed = true;
+ return;
+ }
+
if (!closed) {
if (chunk) {
@@ -327,9 +335,10 @@
length = Integer.parseInt(numberValue.trim(), 16);
} catch (NumberFormatException e) {
// Critical error, unable to parse the chunk length
- length = 0;
+ length = -1;
chunk = false;
- close();
+ endChunk = true;
+ closed = true;
return false;
}