commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestWebappHeaders.java
Date Sat, 13 Jul 2002 09:07:02 GMT
dion        2002/07/13 02:07:02

  Modified:    httpclient/src/test/org/apache/commons/httpclient
                        TestWebappHeaders.java
  Log:
  Patches for adding Host header by Ryan Lubke
  
  Revision  Changes    Path
  1.4       +58 -4     jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappHeaders.java
  
  Index: TestWebappHeaders.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappHeaders.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestWebappHeaders.java	4 Feb 2002 15:26:43 -0000	1.3
  +++ TestWebappHeaders.java	13 Jul 2002 09:07:01 -0000	1.4
  @@ -62,6 +62,7 @@
   
   package org.apache.commons.httpclient;
   
  +import java.net.InetAddress;
   import junit.framework.*;
   import org.apache.commons.httpclient.methods.*;
   
  @@ -180,5 +181,58 @@
           Header h = new Header("HeaderSetByServlet","Yes");
           assertEquals(h,method.getResponseHeader("headersetbyservlet"));
       }
  +
  +    /**
  +     * Test {@link HttpMethodBase.addHostRequestHeader}.
  +     */
  +    public void testHostRequestHeader() throws Exception {
  +        InetAddress addr = InetAddress.getByName(host);
  +        String ip = addr.getHostAddress();
  +        String hostname = addr.getHostName();
  +
  +        HttpClient client = new HttpClient();
  +        GetMethod get = new GetMethod("/" + context);
  +
  +        // Open connection using IP.  Host header should be
  +        // sent, but with no value.
  +        client.startSession(ip, port);
  +        try {
  +            client.executeMethod(get);
  +        } catch (Throwable t) {
  +            t.printStackTrace();
  +            fail("Unable to execute method : " + t.toString());
  +        }
  +        client.endSession();
  +        Header hostHeader = get.getRequestHeader("Host");
  +        assertTrue(hostHeader != null);
  +        assertTrue(hostHeader.getValue().equals(""));
  +
  +        // reset 
  +        get.recycle();
  +        get.setPath("/" + context);
  +
  +        // Open connection using Host.  Host header should
  +        // contain this value (this test will fail if DNS
  +        // is not available. Additionally, if the port is
  +        // something other that 80, then the port value
  +        // should also be present in the header.
  +        client.startSession(hostname, port);
  +        try {
  +            client.executeMethod(get);
  +        } catch (Throwable t) {
  +            t.printStackTrace();
  +            fail("Unable to execute method : " + t.toString());
  +        }
  +        client.endSession();
  +        hostHeader = get.getRequestHeader("Host");
  +        assertTrue(hostHeader != null);
  +        if (port == 80) {
  +            // no port information should be in the value
  +            assertTrue(hostHeader.getValue().equals(hostname));
  +        } else {
  +            assertTrue(hostHeader.getValue().equals(hostname + ":" + port));
  +        }
  +    }
  +
   }
   
  
  
  

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