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 2013/01/07 22:06:36 UTC
svn commit: r1430008 - in /httpcomponents/httpclient/trunk: RELEASE_NOTES.txt
httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java
httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java
Author: olegk
Date: Mon Jan 7 21:06:35 2013
New Revision: 1430008
URL: http://svn.apache.org/viewvc?rev=1430008&view=rev
Log:
HTTPCLIENT-1291: Absolute request URIs without an explicitly specified path are rewritten to have / path
Modified:
httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
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/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=1430008&r1=1430007&r2=1430008&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Mon Jan 7 21:06:35 2013
@@ -1,6 +1,10 @@
Changes in trunk
-------------------
+* [HTTPCLIENT-1291] Absolute request URIs without an explicitly specified path are rewritten
+ to have "/" path).
+ Contributed by Oleg Kalnichevski <olegk at apache.org>
+
* [HTTPCLIENT-900] Don't enforce URI syntax for messages with an explicit target host.
Contributed by Oleg Kalnichevski <olegk at apache.org>
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=1430008&r1=1430007&r2=1430008&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 Mon Jan 7 21:06:35 2013
@@ -33,6 +33,7 @@ import java.util.Stack;
import org.apache.http.HttpHost;
import org.apache.http.annotation.Immutable;
import org.apache.http.util.Args;
+import org.apache.http.util.TextUtils;
/**
* A collection of utilities for {@link URI URIs}, to workaround
@@ -112,7 +113,7 @@ public class URIUtils {
* A convenience method for creating a new {@link URI} whose scheme, host
* and port are taken from the target host, but whose path, query and
* fragment are taken from the existing URI. The fragment is only used if
- * dropFragment is false.
+ * dropFragment is false. The path is set to "/" if not explicitly specified.
*
* @param uri
* Contains the path, query and fragment to use.
@@ -142,6 +143,9 @@ public class URIUtils {
if (dropFragment) {
uribuilder.setFragment(null);
}
+ if (TextUtils.isEmpty(uribuilder.getPath())) {
+ uribuilder.setPath("/");
+ }
return uribuilder.build();
}
@@ -159,7 +163,8 @@ public class URIUtils {
/**
* A convenience method that creates a new {@link URI} whose scheme, host, port, path,
* query are taken from the existing URI, dropping any fragment or user-information.
- * The existing URI is returned unmodified if it has no fragment or user-information.
+ * The path is set to "/" if not explicitly specified. The existing URI is returned
+ * unmodified if it has no fragment or user-information and has a path.
*
* @param uri
* original URI.
@@ -168,8 +173,14 @@ public class URIUtils {
*/
public static URI rewriteURI(final URI uri) throws URISyntaxException {
Args.notNull(uri, "URI");
- if (uri.getFragment() != null || uri.getUserInfo() != null) {
- return new URIBuilder(uri).setFragment(null).setUserInfo(null).build();
+ if (uri.getFragment() != null || uri.getUserInfo() != null
+ || TextUtils.isEmpty(uri.getPath())) {
+ URIBuilder uribuilder = new URIBuilder(uri);
+ uribuilder.setFragment(null).setUserInfo(null);
+ if (TextUtils.isEmpty(uribuilder.getPath())) {
+ uribuilder.setPath("/");
+ }
+ return uribuilder.build();
} else {
return uri;
}
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=1430008&r1=1430007&r2=1430008&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 Mon Jan 7 21:06:35 2013
@@ -55,6 +55,10 @@ public class TestURIUtils {
URI.create("http://thishost/stuff#crap"), target, true).toString());
Assert.assertEquals("http://thathost/stuff#crap", URIUtils.rewriteURI(
URI.create("http://thishost/stuff#crap"), target, false).toString());
+ Assert.assertEquals("http://thathost/", URIUtils.rewriteURI(
+ URI.create("http://thishost#crap"), target, true).toString());
+ Assert.assertEquals("http://thathost/#crap", URIUtils.rewriteURI(
+ URI.create("http://thishost#crap"), target, false).toString());
Assert.assertEquals("/stuff/", URIUtils.rewriteURI(
URI.create("http://thishost//////////////stuff/"), null).toString());
Assert.assertEquals("http://thathost/stuff", URIUtils.rewriteURI(
@@ -63,6 +67,8 @@ public class TestURIUtils {
URI.create("http://thathost/stuff#fragment")).toString());
Assert.assertEquals("http://thathost/stuff", URIUtils.rewriteURI(
URI.create("http://userinfo@thathost/stuff#fragment")).toString());
+ Assert.assertEquals("http://thathost/", URIUtils.rewriteURI(
+ URI.create("http://thathost")).toString());
}
@Test