hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeffrey Dever <jsde...@sympatico.ca>
Subject Re: [PATCH] Sending IP addresses in Host header
Date Mon, 16 Dec 2002 05:16:53 GMT
Committed.

Eric Johnson wrote:

> Oleg noted in a previous email that HttpClient sends a blank Host 
> header in the event that the "host" is an IP address rather than a 
> name.  This behavior, in Oleg's interpretation and mine, is incorrect, 
> and a IP address should also be sent on the Host header.  Both Mozilla 
> and IE appear to send IP addresses in the Host header, also 
> disagreeing with the current HttpClient implementation.
>
> This change to send a blank occurred with a patch from Ryan Lubke 
> (according to CVS logs) that was applied on 7/13/2002.  Ryan, if 
> you're out there observing, your feedback would be appreciated.
>
> The attached patch will change HttpClient to be consistent with the 
> aforementioned browsers, (and I think with the RFC) as well as fixing 
> some issues with the test cases.
>
> -Eric Johnson
>
>------------------------------------------------------------------------
>
>? host.header.patch
>? lib/junit.jar
>? lib/servlet.jar
>Index: src/java/org/apache/commons/httpclient/HttpMethodBase.java
>===================================================================
>RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
>retrieving revision 1.87
>diff -u -r1.87 HttpMethodBase.java
>--- src/java/org/apache/commons/httpclient/HttpMethodBase.java	11 Dec 2002 13:21:43 -0000
1.87
>+++ src/java/org/apache/commons/httpclient/HttpMethodBase.java	13 Dec 2002 15:03:35 -0000
>@@ -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");
>         }
>Index: src/test/org/apache/commons/httpclient/TestGetMethodLocal.java
>===================================================================
>RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestGetMethodLocal.java,v
>retrieving revision 1.4
>diff -u -r1.4 TestGetMethodLocal.java
>--- src/test/org/apache/commons/httpclient/TestGetMethodLocal.java	9 Dec 2002 09:16:17
-0000	1.4
>+++ src/test/org/apache/commons/httpclient/TestGetMethodLocal.java	13 Dec 2002 15:03:35
-0000
>@@ -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
> 
>Index: src/test/org/apache/commons/httpclient/TestHttpClientLocalHost.java
>===================================================================
>RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpClientLocalHost.java,v
>retrieving revision 1.5
>diff -u -r1.5 TestHttpClientLocalHost.java
>--- src/test/org/apache/commons/httpclient/TestHttpClientLocalHost.java	9 Dec 2002 09:16:17
-0000	1.5
>+++ src/test/org/apache/commons/httpclient/TestHttpClientLocalHost.java	13 Dec 2002 15:03:36
-0000
>@@ -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
> 
>Index: src/test/org/apache/commons/httpclient/TestMethodsLocalHost.java
>===================================================================
>RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsLocalHost.java,v
>retrieving revision 1.5
>diff -u -r1.5 TestMethodsLocalHost.java
>--- src/test/org/apache/commons/httpclient/TestMethodsLocalHost.java	9 Dec 2002 09:16:17
-0000	1.5
>+++ src/test/org/apache/commons/httpclient/TestMethodsLocalHost.java	13 Dec 2002 15:03:36
-0000
>@@ -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
> 
>Index: src/test/org/apache/commons/httpclient/TestWebappHeaders.java
>===================================================================
>RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappHeaders.java,v
>retrieving revision 1.4
>diff -u -r1.4 TestWebappHeaders.java
>--- src/test/org/apache/commons/httpclient/TestWebappHeaders.java	13 Jul 2002 09:07:01
-0000	1.4
>+++ src/test/org/apache/commons/httpclient/TestWebappHeaders.java	13 Dec 2002 15:03:36
-0000
>@@ -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:   <mailto:commons-httpclient-dev-unsubscribe@jakarta.apache.org>
>For additional commands, e-mail: <mailto:commons-httpclient-dev-help@jakarta.apache.org>
>


Mime
View raw message