mbecke 2003/07/10 18:07:30 Modified: httpclient/src/java/org/apache/commons/httpclient HttpMethodBase.java Log: One more try at handling non chunked transfer encodings. PR: 21378 Submitted by: Oleg Kalnichevski Reviewed by: Michael Becke Revision Changes Path 1.164 +19 -21 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java Index: HttpMethodBase.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v retrieving revision 1.163 retrieving revision 1.164 diff -u -r1.163 -r1.164 --- HttpMethodBase.java 8 Jul 2003 21:59:18 -0000 1.163 +++ HttpMethodBase.java 11 Jul 2003 01:07:29 -0000 1.164 @@ -71,6 +71,7 @@ import java.util.BitSet; import java.util.HashSet; import java.util.Set; + import org.apache.commons.httpclient.auth.AuthScheme; import org.apache.commons.httpclient.auth.AuthenticationException; import org.apache.commons.httpclient.auth.HttpAuthenticator; @@ -2041,26 +2042,23 @@ is = new WireLogInputStream(is); } InputStream result = null; - Header[] transferEncodingHeaders = responseHeaders.getHeaders("Transfer-Encoding"); + Header transferEncodingHeader = responseHeaders.getFirstHeader("Transfer-Encoding"); // We use Transfer-Encoding if present and ignore Content-Length. // RFC2616, 4.4 item number 3 - if (transferEncodingHeaders.length > 0) { - boolean containsChunked = false; - for (int i = 0; i < transferEncodingHeaders.length; i++) { - String encoding = transferEncodingHeaders[i].getValue(); - if ("chunked".equalsIgnoreCase(encoding)) { - containsChunked = true; - break; - } else if ("identity".equalsIgnoreCase(encoding)) { - //No content transformation needed - } else { - if (LOG.isWarnEnabled()) { - LOG.warn("Unsupported transfer encoding: " + encoding); - } + if (transferEncodingHeader != null) { + + String transferEncoding = transferEncodingHeader.getValue(); + if (!"chunked".equalsIgnoreCase(transferEncoding) + && !"identity".equalsIgnoreCase(transferEncoding)) { + if (LOG.isWarnEnabled()) { + LOG.warn("Unsupported transfer encoding: " + transferEncoding); } } - if (containsChunked) { - // Some HTTP servers do not bother sending a closing chunk + HeaderElement[] encodings = transferEncodingHeader.getValues(); + // The chunked encoding must be the last one applied + // RFC2616, 14.41 + int len = encodings.length; + if ((len > 0) && ("chunked".equalsIgnoreCase(encodings[len - 1].getName()))) { // if response body is empty if (conn.isResponseAvailable(conn.getSoTimeout())) { result = new ChunkedInputStream(is, this); @@ -2074,7 +2072,7 @@ } else { if (isStrictMode() && LOG.isWarnEnabled()) { LOG.warn("Transfer-Encoding is set but does not contain \"chunked\": " - + getResponseHeader("Transfer-Encoding")); + + transferEncoding); } // The connection must be terminated by closing // the socket as per RFC 2616, 3.6
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]