You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2010/04/03 20:16:41 UTC
svn commit: r930558 - in /httpcomponents/httpclient/trunk/httpclient/src:
main/java/org/apache/http/client/utils/URIUtils.java
test/java/org/apache/http/client/utils/TestURIUtils.java
Author: olegk
Date: Sat Apr 3 18:16:40 2010
New Revision: 930558
URL: http://svn.apache.org/viewvc?rev=930558&view=rev
Log:
HTTPCLIENT-929: Request with two forward slashes for path fails
Modified:
httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java
httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java
Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java?rev=930558&r1=930557&r2=930558&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java Sat Apr 3 18:16:40 2010
@@ -134,7 +134,7 @@ public class URIUtils {
target.getSchemeName(),
target.getHostName(),
target.getPort(),
- uri.getRawPath(),
+ normalizePath(uri.getRawPath()),
uri.getRawQuery(),
dropFragment ? null : uri.getRawFragment());
} else {
@@ -142,12 +142,33 @@ public class URIUtils {
null,
null,
-1,
- uri.getRawPath(),
+ normalizePath(uri.getRawPath()),
uri.getRawQuery(),
dropFragment ? null : uri.getRawFragment());
}
}
+ private static String normalizePath(final String path) {
+ if (path == null) {
+ return null;
+ }
+ StringBuilder buffer = new StringBuilder(path.length());
+ boolean gotslash = false;
+ for (int i = 0; i < path.length(); i++) {
+ char ch = path.charAt(i);
+ if (ch == '/') {
+ if (!gotslash) {
+ buffer.append(ch);
+ gotslash = true;
+ }
+ } else {
+ buffer.append(ch);
+ gotslash = false;
+ }
+ }
+ return buffer.toString();
+ }
+
/**
* A convenience method for
* {@link URIUtils#rewriteURI(URI, HttpHost, boolean)} that always keeps the
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java?rev=930558&r1=930557&r2=930558&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java Sat Apr 3 18:16:40 2010
@@ -27,6 +27,8 @@ package org.apache.http.client.utils;
import java.net.URI;
+import org.apache.http.HttpHost;
+
import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestCase;
@@ -53,6 +55,39 @@ public class TestURIUtils extends TestCa
return new TestSuite(TestURIUtils.class);
}
+ public void testRewite00() throws Exception {
+ URI uri = URI.create("http://thishost/stuff");
+ HttpHost target = new HttpHost("thathost", -1);
+ Assert.assertEquals("http://thathost/stuff", URIUtils.rewriteURI(uri, target).toString());
+ }
+
+ public void testRewite01() throws Exception {
+ URI uri = URI.create("http://thishost/stuff");
+ Assert.assertEquals("/stuff", URIUtils.rewriteURI(uri, null).toString());
+ }
+
+ public void testRewite02() throws Exception {
+ URI uri = URI.create("http://thishost//");
+ Assert.assertEquals("/", URIUtils.rewriteURI(uri, null).toString());
+ }
+
+ public void testRewite03() throws Exception {
+ URI uri = URI.create("http://thishost//stuff///morestuff");
+ Assert.assertEquals("/stuff/morestuff", URIUtils.rewriteURI(uri, null).toString());
+ }
+
+ public void testRewite04() throws Exception {
+ URI uri = URI.create("http://thishost/stuff#crap");
+ HttpHost target = new HttpHost("thathost", -1);
+ Assert.assertEquals("http://thathost/stuff", URIUtils.rewriteURI(uri, target, true).toString());
+ }
+
+ public void testRewite05() throws Exception {
+ URI uri = URI.create("http://thishost/stuff#crap");
+ HttpHost target = new HttpHost("thathost", -1);
+ Assert.assertEquals("http://thathost/stuff#crap", URIUtils.rewriteURI(uri, target, false).toString());
+ }
+
public void testResolve00() {
Assert.assertEquals("g:h", URIUtils.resolve(this.baseURI, "g:h").toString());
}