You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by di...@apache.org on 2002/07/13 11:07:02 UTC
cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestWebappHeaders.java
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: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>