You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by js...@apache.org on 2002/12/16 06:16:05 UTC

cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestGetMethodLocal.java TestHttpClientLocalHost.java TestMethodsLocalHost.java TestWebappHeaders.java

jsdever     2002/12/15 21:16:04

  Modified:    httpclient/src/java/org/apache/commons/httpclient
                        HttpMethodBase.java
               httpclient/src/test/org/apache/commons/httpclient
                        TestGetMethodLocal.java
                        TestHttpClientLocalHost.java
                        TestMethodsLocalHost.java TestWebappHeaders.java
  Log:
  Send IP address as the Host header instead of blank.
  
  Contributed by: Eric Johnson
  
  Revision  Changes    Path
  1.90      +12 -9     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.89
  retrieving revision 1.90
  diff -u -r1.89 -r1.90
  --- HttpMethodBase.java	16 Dec 2002 03:51:04 -0000	1.89
  +++ HttpMethodBase.java	16 Dec 2002 05:16:04 -0000	1.90
  @@ -1258,11 +1258,14 @@
               return;
           }
   
  -        if (isIpAddress(host)) {
  -            log.debug("Adding empty Host request header: host is an ipaddress");
  -            setRequestHeader("Host", "");
  -            return;
  -        }
  +        // Note: RFC 2616 uses the term "internet host name" for what goes on the
  +        // host line.  It would seem to imply that host should be blank if the
  +        // host is a number instead of an name.  Based on the behavior of web
  +        // browsers, and the fact that RFC 2616 never defines the phrase "internet
  +        // host name", and the bad behavior of HttpClient that follows if we
  +        // send blank, I interpret this as a small misstatement in the RFC, where
  +        // they meant to say "internet host".  So IP numbers get sent as host
  +        // entries too. -- Eric Johnson 12/13/2002
           if (log.isDebugEnabled()) {
               log.debug("Adding Host request header");
           }
  
  
  
  1.5       +21 -10    jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestGetMethodLocal.java
  
  Index: TestGetMethodLocal.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestGetMethodLocal.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestGetMethodLocal.java	9 Dec 2002 09:16:17 -0000	1.4
  +++ TestGetMethodLocal.java	16 Dec 2002 05:16:04 -0000	1.5
  @@ -86,12 +86,13 @@
   public class TestGetMethodLocal extends TestCase {
   
   
  -    // -------------------------------------------------------------- Constants
  +    // -------------------------------------------------------------- Environment
  +
  +    public static String getTestHost() {
  +        return System.getProperty("httpclient.test.localHost","127.0.0.1");
  +    }
   
  -    private static final String host = System.getProperty("httpclient.test.localHost","127.0.0.1");
  -    private static final String webAppContext = System.getProperty("httpclient.test.webappContext");
  -    private static final int port;
  -    static {
  +    public static int getTestPort() {
           String portString = System.getProperty("httpclient.test.localPort","8080");
           int tempPort = 8080;
           try {
  @@ -99,8 +100,18 @@
           } catch(Exception e) {
               tempPort = 8080;
           }
  -        port = tempPort;
  +        return tempPort;
  +
       }
  +
  +    public static String getTestContext() {
  +        return System.getProperty("httpclient.test.webappContext");
  +    }
  +    // -------------------------------------------------------------- Constants
  +
  +    private static final String host = getTestHost();
  +    private static final String webAppContext = getTestContext();
  +    private static final int port = getTestPort();
   
       // ------------------------------------------------------------ Constructor
   
  
  
  
  1.6       +7 -8      jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpClientLocalHost.java
  
  Index: TestHttpClientLocalHost.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpClientLocalHost.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TestHttpClientLocalHost.java	9 Dec 2002 09:16:17 -0000	1.5
  +++ TestHttpClientLocalHost.java	16 Dec 2002 05:16:04 -0000	1.6
  @@ -83,10 +83,9 @@
   
       // -------------------------------------------------------------- Constants
   
  -
  -    private static final String host = "127.0.0.1";
  -    private static final int port = 8080;
  -    private static final String webAppContext = System.getProperty("httpclient.test.webappContext");
  +    private static final String host = TestGetMethodLocal.getTestHost();
  +    private static final String webAppContext = TestGetMethodLocal.getTestContext();
  +    private static final int port = TestGetMethodLocal.getTestPort();
   
       // ------------------------------------------------------------ Constructor
   
  
  
  
  1.6       +7 -9      jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsLocalHost.java
  
  Index: TestMethodsLocalHost.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsLocalHost.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TestMethodsLocalHost.java	9 Dec 2002 09:16:17 -0000	1.5
  +++ TestMethodsLocalHost.java	16 Dec 2002 05:16:04 -0000	1.6
  @@ -87,11 +87,9 @@
   
       // -------------------------------------------------------------- Constants
   
  -
  -    private static final String webAppContext = System.getProperty("httpclient.test.webappContext");
  -    private static final String host = "127.0.0.1";
  -    private static final int port = 8080;
  -
  +    private static final String webAppContext = TestGetMethodLocal.getTestContext();
  +    private static final String host = TestGetMethodLocal.getTestHost();
  +    private static final int port = TestGetMethodLocal.getTestPort();
   
       // ------------------------------------------------------------ Constructor
   
  
  
  
  1.5       +8 -7      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestWebappHeaders.java	13 Jul 2002 09:07:01 -0000	1.4
  +++ TestWebappHeaders.java	16 Dec 2002 05:16:04 -0000	1.5
  @@ -193,8 +193,10 @@
           HttpClient client = new HttpClient();
           GetMethod get = new GetMethod("/" + context);
   
  -        // Open connection using IP.  Host header should be
  -        // sent, but with no value.
  +        // Open connection using IP.  Host header should be sent
  +        // Note: RFC 2616 is somewhat unclear on whether a host should
  +        // be sent in this context - however, both Mozilla and IE send
  +        // the header for an IP address, instead of sending blank.
           client.startSession(ip, port);
           try {
               client.executeMethod(get);
  @@ -205,7 +207,6 @@
           client.endSession();
           Header hostHeader = get.getRequestHeader("Host");
           assertTrue(hostHeader != null);
  -        assertTrue(hostHeader.getValue().equals(""));
   
           // reset 
           get.recycle();
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>