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/test/org/apache/commons/httpclient TestStatusLine.java
Date Fri, 18 Oct 2002 13:43:46 GMT
jsdever     2002/10/18 06:43:45

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        StatusLine.java
               httpclient/src/test/org/apache/commons/httpclient
                        TestStatusLine.java
  Log:
  Allow space after the HTTP-Version in the status line.
  Workaround for bug in Microsoft Proxy Server v2.0
  
  Suggested by: Thai Thanh Ha
  Contributed by: Jeff Dever
  
  Revision  Changes    Path
  1.4       +14 -12    jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/StatusLine.java
  
  Index: StatusLine.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/StatusLine.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StatusLine.java	18 Oct 2002 09:18:21 -0000	1.3
  +++ StatusLine.java	18 Oct 2002 13:43:45 -0000	1.4
  @@ -136,13 +136,18 @@
           }
           this.httpVersion = (statusLine.substring(0, at)).toUpperCase();
   
  +        //advance through spaces
  +        while (statusLine.charAt(at) == ' ') {
  +            at++;
  +        }
  +
           //handle the Status-Code
  -        int to = statusLine.indexOf(" ", at + 1);
  +        int to = statusLine.indexOf(" ", at);
           if (to < 0) {
               to = length;
           }
           try {
  -            this.statusCode = Integer.parseInt(statusLine.substring(at+1, to));
  +            this.statusCode = Integer.parseInt(statusLine.substring(at, to));
           } catch (NumberFormatException e) {
               throw new HttpException(
                   "Unable to parse status code from status line: '" 
  @@ -150,13 +155,10 @@
           }
   
           //handle the Reason-Phrase
  +        at = to + 1;
           try {
  -            if (to < length) {
  -                if (statusLine.endsWith("\r\n")) {
  -                    this.reasonPhrase = statusLine.substring(to+1, length-2);
  -                } else {
  -                    this.reasonPhrase = statusLine.substring(to+1);
  -                }
  +            if (at < length) {
  +                this.reasonPhrase = statusLine.substring(at).trim();
               } else {
                   this.reasonPhrase = "";
               }
  
  
  
  1.3       +9 -4      jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestStatusLine.java
  
  Index: TestStatusLine.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestStatusLine.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestStatusLine.java	18 Oct 2002 09:18:21 -0000	1.2
  +++ TestStatusLine.java	18 Oct 2002 13:43:45 -0000	1.3
  @@ -126,6 +126,11 @@
           statusLine = new StatusLine("HTTP/1.1 200");
           assertEquals(200, statusLine.getStatusCode());
           assertEquals("", statusLine.getReasonPhrase());
  +
  +        //this is not strictly valid, but is lienent
  +        statusLine = new StatusLine("HTTP/1.1     200 OK");
  +        assertEquals(200, statusLine.getStatusCode());
  +        assertEquals("OK", statusLine.getReasonPhrase());
       }
   
       public void testFailure() throws Exception {
  
  
  

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


Mime
View raw message