commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsde...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/java/org/apache/commons/httpclient HttpConnection.java HttpMethodBase.java
Date Sat, 08 Feb 2003 01:12:15 GMT
jsdever     2003/02/07 17:12:15

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpConnection.java HttpMethodBase.java
  Log:
  Fix for bug 16846
  
  Bug: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16864
  
  changeLog:
  - now requires the a "\r\n" be present as a pair to terminate the line
  - if the end of stream is read before a \n\r is found, the data read up untill that point
will be returned
  - minimize the number of checks in the read loop to try and speed it up a bit
  
  Contributed by: Jeff Dever
  
  Revision  Changes    Path
  1.41      +18 -19    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java
  
  Index: HttpConnection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- HttpConnection.java	31 Jan 2003 23:23:13 -0000	1.40
  +++ HttpConnection.java	8 Feb 2003 01:12:15 -0000	1.41
  @@ -101,7 +101,7 @@
    * @author Rod Waldhoff
    * @author Sean C. Sullivan
    * @author Ortwin Glück
  - * @author Jeff Dever
  + * @author <a href="mailto:jsdever@apache.org">Jeff Dever</a>
    * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
    * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
    * 
  @@ -873,6 +873,9 @@
   
       /**
        * Read up to <tt>"\r\n"</tt> from my (unchunked) input stream.
  +     * If the stream ends before the line terminator is found,
  +     * the last part of the string will still be returned.
  +     * '\r' and '\n' are allowed to appear individually in the stream.
        *
        * @throws IllegalStateException if I am not connected
        * @throws IOException if an I/O problem occurs
  @@ -883,25 +886,21 @@
   
           assertOpen();
           StringBuffer buf = new StringBuffer();
  -        while (true) {
  -            int ch = inputStream.read();
  -            if (ch < 0) {
  -                if (buf.length() == 0) {
  -                    return null;
  -                } else {
  +        int ch = inputStream.read();
  +        while (ch >= 0) {
  +            if (ch == '\r') {
  +                ch = inputStream.read();
  +                if (ch == '\n') {
                       break;
  +                } else {
  +                    buf.append('\r');
                   }
  -            } else if (ch == '\r') {
  -                //                LOG.debug("HttpConnection.readLine() found \\r, continuing");
  -                continue;
  -            } else if (ch == '\n') {
  -                //                LOG.debug("HttpConnection.readLine() found \\n, breaking");
  -                break;
               }
               buf.append((char) ch);
  +            ch = inputStream.read();
           }
  -        if (WIRE_LOG.isDebugEnabled() && buf.length() > 0) {
  -            WIRE_LOG.debug("<< \"" + buf.toString() + "\" [\\r\\n]");
  +        if (WIRE_LOG.isDebugEnabled()) {
  +            WIRE_LOG.debug("<< \"" + buf.toString() + (ch>0 ? "\" [\\r\\n]" :
""));
           }
           return (buf.toString());
       }
  
  
  
  1.109     +11 -7     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.108
  retrieving revision 1.109
  diff -u -r1.108 -r1.109
  --- HttpMethodBase.java	2 Feb 2003 04:30:13 -0000	1.108
  +++ HttpMethodBase.java	8 Feb 2003 01:12:15 -0000	1.109
  @@ -1910,8 +1910,7 @@
        */
       protected void readStatusLine(HttpState state, HttpConnection conn)
       throws IOException, HttpRecoverableException, HttpException {
  -        LOG.trace(
  -            "enter HttpMethodBase.readStatusLine(HttpState, HttpConnection)");
  +        LOG.trace("enter HttpMethodBase.readStatusLine(HttpState, HttpConnection)");
   
           //read out the HTTP status string
           String statusString = conn.readLine();
  @@ -2166,6 +2165,7 @@
   
       /**
        * Sets the specified response header.
  +     * Logs a warning if the header name is null.
        *
        * @param header the header to set.
        *
  @@ -2175,7 +2175,11 @@
           if (header == null) {
               return;
           }
  -        responseHeaders.put(header.getName().toLowerCase(), header);
  +        if (header.getName() == null) {
  +            LOG.warn("Invalid header found");
  +        } else {
  +            responseHeaders.put(header.getName().toLowerCase(), header);
  +        }
       }
   
       /**
  
  
  

---------------------------------------------------------------------
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