--- commons-httpclient-3.0.1/src/java/org/apache/commons/httpclient/Cookie.java.orig	2010-03-26 11:26:03.000000000 -0400
+++ commons-httpclient-3.0.1/src/java/org/apache/commons/httpclient/Cookie.java	2010-03-26 12:32:35.000000000 -0400
@@ -231,15 +231,42 @@
      */
     public void setDomain(String domain) {
         if (domain != null) {
-            int ndx = domain.indexOf(":");
-            if (ndx != -1) {
-              domain = domain.substring(0, ndx);
-            }
+
+	    // check for IPv6 literal
+	    if (countColons(domain) >= 2) {
+		if (domain.indexOf("]") == -1) {
+		    // add brackets so that matching works
+		    cookieDomain = ("[" + domain + "]").toLowerCase() ;
+		    return ;
+		}
+	    }
+	    
+	    int ndx = domain.lastIndexOf(":");
+	    if ((ndx >= 0) && !domain.endsWith("]")) {
+		domain = domain.substring(0, ndx);
+	    }
+	    
             cookieDomain = domain.toLowerCase();
         }
     }
 
-
+    private int countColons(String s) {
+	
+	String tmpstr = new String(s) ;
+	int count = 0 ;
+	int index = 0 ;
+	
+	index = tmpstr.indexOf(":") ;
+	while (index >= 0) {
+	    count++ ;
+	    tmpstr = tmpstr.substring(index+1) ;
+	    index = tmpstr.indexOf(":") ;
+	}
+	
+	return count ;
+    } 	
+    
+    
     /**
      * Returns the path attribute of the cookie
      * 
