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/test/org/apache/commons/httpclient TestResponseHeaders.java
Date Tue, 10 Jun 2003 22:42:52 GMT
mbecke      2003/06/10 15:42:52

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpMethodBase.java
               httpclient/src/test/org/apache/commons/httpclient
                        TestResponseHeaders.java
  Log:
  Duplicate connection headers are now handled correctly.
  PR: 20569
  Reviewed by: Oleg Kalnichevski
  
  Revision  Changes    Path
  1.151     +6 -6      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.150
  retrieving revision 1.151
  diff -u -r1.150 -r1.151
  --- HttpMethodBase.java	26 May 2003 22:07:21 -0000	1.150
  +++ HttpMethodBase.java	10 Jun 2003 22:42:51 -0000	1.151
  @@ -883,13 +883,13 @@
           // In case being connected via a proxy server
           if (!conn.isTransparent()) {
               // Check for 'proxy-connection' directive
  -            connectionHeader = getResponseHeader("proxy-connection");
  +            connectionHeader = responseHeaders.getFirstHeader("proxy-connection");
           }
           // In all cases Check for 'connection' directive
           // some non-complaint proxy servers send it instread of
           // expected 'proxy-connection' directive
           if (connectionHeader == null) {
  -            connectionHeader = getResponseHeader("connection");
  +            connectionHeader = responseHeaders.getFirstHeader("connection");
           }
           if (connectionHeader != null) {
               if (connectionHeader.getValue().equalsIgnoreCase("close")) {
  
  
  
  1.7       +72 -4     jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestResponseHeaders.java
  
  Index: TestResponseHeaders.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestResponseHeaders.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestResponseHeaders.java	23 Jan 2003 22:48:27 -0000	1.6
  +++ TestResponseHeaders.java	10 Jun 2003 22:42:52 -0000	1.7
  @@ -62,6 +62,8 @@
   
   package org.apache.commons.httpclient;
   
  +import org.apache.commons.httpclient.methods.GetMethod;
  +
   import junit.framework.Test;
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
  @@ -142,6 +144,72 @@
           method.execute(state, conn);
           assertNotNull( "Response body is null.", method.getResponseBodyAsStream() );
                   
  +    }
  +
  +    public void testDuplicateProxyConnection() throws Exception {
  +        
  +        SimpleHttpConnection conn = new SimpleHttpConnection();
  +        String headers = 
  +            "HTTP/1.1 200 OK\r\n"
  +            + "proxy-connection: close\r\n"
  +            + "proxy-connection: close\r\n"
  +            + "\r\n";
  +
  +        conn.addResponse(headers, "");
  +        conn.setProxyHost("proxy");
  +        conn.setProxyPort(1);
  +        GetMethod method = new GetMethod("/");
  +        method.execute(new HttpState(), conn);
  +        method.getResponseBodyAsString();
  +        
  +        assertFalse(conn.isOpen());
  +        
  +        conn = new SimpleHttpConnection();
  +        headers = 
  +            "HTTP/1.0 200 OK\r\n"
  +            + "proxy-connection: keep-alive\r\n"
  +            + "proxy-connection: keep-alive\r\n"
  +            + "\r\n";
  +
  +        conn.addResponse(headers, "");
  +        conn.setProxyHost("proxy");
  +        conn.setProxyPort(1);
  +        method = new GetMethod("/");
  +        method.execute(new HttpState(), conn);
  +        method.getResponseBodyAsString();
  +        
  +        assertTrue(conn.isOpen());        
  +    }
  +
  +    public void testDuplicateConnection() throws Exception {
  +        
  +        SimpleHttpConnection conn = new SimpleHttpConnection();
  +        String headers = 
  +            "HTTP/1.1 200 OK\r\n"
  +            + "Connection: close\r\n"
  +            + "Connection: close\r\n"
  +            + "\r\n";
  +
  +        conn.addResponse(headers, "");
  +        GetMethod method = new GetMethod("/");
  +        method.execute(new HttpState(), conn);
  +        method.getResponseBodyAsString();
  +        
  +        assertFalse(conn.isOpen());
  +
  +        conn = new SimpleHttpConnection();
  +        headers = 
  +            "HTTP/1.0 200 OK\r\n"
  +            +"Connection: keep-alive\r\n"
  +            +"Connection: keep-alive\r\n"
  +            +"\r\n";
  +
  +        conn.addResponse(headers, "");
  +        method = new GetMethod("/");
  +        method.execute(new HttpState(), conn);
  +        method.getResponseBodyAsString();
  +        
  +        assertTrue(conn.isOpen());
       }
   
       public void testNullHeaders() throws Exception {
  
  
  

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