commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mbe...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/java/org/apache/commons/httpclient HttpMethodBase.java
Date Tue, 08 Jul 2003 11:51:45 GMT
mbecke      2003/07/08 04:51:45

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpMethodBase.java
  Log:
  Multiple transfer encoding headers are now handled properly.
  
  PR: 21378
  Submitted by: Oleg Kalnichevski and Michael Becke
  
  Revision  Changes    Path
  1.161     +30 -8     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.160
  retrieving revision 1.161
  diff -u -r1.160 -r1.161
  --- HttpMethodBase.java	5 Jul 2003 18:30:27 -0000	1.160
  +++ HttpMethodBase.java	8 Jul 2003 11:51:45 -0000	1.161
  @@ -2013,27 +2013,49 @@
           LOG.trace("enter HttpMethodBase.readResponseBody(HttpState, HttpConnection)");
   
           responseBody = null; // is this desired?
  -        Header transferEncodingHeader = getResponseHeader("Transfer-Encoding");
           InputStream is = conn.getResponseInputStream();
           if (Wire.enabled()) {
               is = new WireLogInputStream(is);
           }
           InputStream result = null;
  +        Header[] transferEncodingHeaders = responseHeaders.getHeaders("Transfer-Encoding");
           // We use Transfer-Encoding if present and ignore Content-Length.
           // RFC2616, 4.4 item number 3
  -        if (transferEncodingHeader != null) {
  -            if ("chunked".equalsIgnoreCase(transferEncodingHeader.getValue())) {
  +        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 (containsChunked) {
                   // Some HTTP servers do not bother sending a closing chunk 
                   // if response body is empty
                   if (conn.isResponseAvailable(conn.getSoTimeout())) {
                       result = new ChunkedInputStream(is, this);
                   } else {
  -                    if (this.isStrictMode()) {
  +                    if (isStrictMode()) {
                           throw new HttpException("Chunk-encoded body declared but not sent");
                       } else {
                           LOG.warn("Chunk-encoded body missing");
                       }
                   }
  +            } else {
  +                if (isStrictMode() && LOG.isWarnEnabled()) {
  +                    LOG.warn("Transfer-Encoding is set but does not contain \"chunked\":
"
  +                        + getResponseHeader("Transfer-Encoding"));
  +                }
  +                // we assume that the response connection will be terminated by closing

  +                // the socket as per RFC 2616, 3.6
  +                result = is;  
               }
           } else {
               int expectedLength = getResponseContentLength();
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message