HTTPCLIENT-929: Request with two forward slashes for path fails
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@930558 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c1c6ba636a
commit
ba748bf20c
|
@ -134,7 +134,7 @@ public class URIUtils {
|
||||||
target.getSchemeName(),
|
target.getSchemeName(),
|
||||||
target.getHostName(),
|
target.getHostName(),
|
||||||
target.getPort(),
|
target.getPort(),
|
||||||
uri.getRawPath(),
|
normalizePath(uri.getRawPath()),
|
||||||
uri.getRawQuery(),
|
uri.getRawQuery(),
|
||||||
dropFragment ? null : uri.getRawFragment());
|
dropFragment ? null : uri.getRawFragment());
|
||||||
} else {
|
} else {
|
||||||
|
@ -142,12 +142,33 @@ public class URIUtils {
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
-1,
|
-1,
|
||||||
uri.getRawPath(),
|
normalizePath(uri.getRawPath()),
|
||||||
uri.getRawQuery(),
|
uri.getRawQuery(),
|
||||||
dropFragment ? null : uri.getRawFragment());
|
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
|
* A convenience method for
|
||||||
* {@link URIUtils#rewriteURI(URI, HttpHost, boolean)} that always keeps the
|
* {@link URIUtils#rewriteURI(URI, HttpHost, boolean)} that always keeps the
|
||||||
|
|
|
@ -27,6 +27,8 @@ package org.apache.http.client.utils;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
|
import org.apache.http.HttpHost;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
@ -53,6 +55,39 @@ public class TestURIUtils extends TestCase {
|
||||||
return new TestSuite(TestURIUtils.class);
|
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() {
|
public void testResolve00() {
|
||||||
Assert.assertEquals("g:h", URIUtils.resolve(this.baseURI, "g:h").toString());
|
Assert.assertEquals("g:h", URIUtils.resolve(this.baseURI, "g:h").toString());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue