Index: src/test/org/apache/commons/httpclient/TestURI.java =================================================================== --- src/test/org/apache/commons/httpclient/TestURI.java (revision 358328) +++ src/test/org/apache/commons/httpclient/TestURI.java (working copy) @@ -181,6 +181,12 @@ } + public void testTestURIAuthorityString() throws Exception { + URI url = new URI("ftp", "user:password", "localhost", -1, "/"); + assertEquals("ftp://user:password@localhost/", url.toString()); + assertEquals("user:password@localhost", url.getAuthority()); + } + public void testTestHttpUrlAuthorityString() throws Exception { HttpURL url = new HttpURL("localhost", -1, "/"); assertEquals("http://localhost/", url.toString()); Index: src/java/org/apache/commons/httpclient/URI.java =================================================================== --- src/java/org/apache/commons/httpclient/URI.java (revision 358328) +++ src/java/org/apache/commons/httpclient/URI.java (working copy) @@ -2263,17 +2263,7 @@ if (_is_net_path) { buf.append("//"); if (_authority != null) { // has_authority - if (_userinfo != null) { // by default, remove userinfo part - if (_host != null) { - buf.append(_host); - if (_port != -1) { - buf.append(':'); - buf.append(_port); - } - } - } else { - buf.append(_authority); - } + buf.append(_authority); } } if (_opaque != null && _is_opaque_part) { Index: src/java/org/apache/commons/httpclient/HttpURL.java =================================================================== --- src/java/org/apache/commons/httpclient/HttpURL.java (revision 358328) +++ src/java/org/apache/commons/httpclient/HttpURL.java (working copy) @@ -828,5 +828,51 @@ } } + /** + * Once it's parsed successfully, set this URI. + * + * @see #getRawURI + */ + protected void setURI() { + // set _uri + StringBuffer buf = new StringBuffer(); + // ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))? + if (_scheme != null) { + buf.append(_scheme); + buf.append(':'); + } + if (_is_net_path) { + buf.append("//"); + if (_authority != null) { // has_authority + if (_userinfo != null) { // by default, remove userinfo part + if (_host != null) { + buf.append(_host); + if (_port != -1) { + buf.append(':'); + buf.append(_port); + } + } + } else { + buf.append(_authority); + } + } + } + if (_opaque != null && _is_opaque_part) { + buf.append(_opaque); + } else if (_path != null) { + // _is_hier_part or _is_relativeURI + if (_path.length != 0) { + buf.append(_path); + } + } + if (_query != null) { // has_query + buf.append('?'); + buf.append(_query); + } + // ignore the fragment identifier + _uri = buf.toString().toCharArray(); + hash = 0; + } + }