hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1430006 - in /httpcomponents/httpclient/branches/4.2.x: 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
Date Mon, 07 Jan 2013 21:06:04 GMT
Author: olegk
Date: Mon Jan  7 21:06:03 2013
New Revision: 1430006

URL: http://svn.apache.org/viewvc?rev=1430006&view=rev
Log:
HTTPCLIENT-1291: Absolute request URIs without an explicitly specified path are rewritten
to have / path

Modified:
    httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt
    httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java
    httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java

Modified: httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt?rev=1430006&r1=1430005&r2=1430006&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt Mon Jan  7 21:06:03 2013
@@ -10,6 +10,10 @@ Users of HttpClient 4.x are advised to u
 Changelog
 -------------------
 
+* [HTTPCLIENT-1291] Absolute request URIs without an explicitly specified path are rewritten

+  to have "/" path).  
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPCLIENT-1286] Request URI rewriting is inconsistent - URI fragments are not removed

   from absolute request URIs.  
   Contributed by Oleg Kalnichevski <olegk at apache.org>

Modified: httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java?rev=1430006&r1=1430005&r2=1430006&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java
(original)
+++ httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/client/utils/URIUtils.java
Mon Jan  7 21:06:03 2013
@@ -112,7 +112,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.
@@ -144,6 +144,9 @@ public class URIUtils {
         if (dropFragment) {
             uribuilder.setFragment(null);
         }
+        if (uribuilder.getPath() == null || uribuilder.getPath().length() == 0) {
+            uribuilder.setPath("/");
+        }
         return uribuilder.build();
     }
 
@@ -161,7 +164,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.
@@ -172,8 +176,14 @@ public class URIUtils {
         if (uri == null) {
             throw new IllegalArgumentException("URI may not be null");
         }
-        if (uri.getFragment() != null || uri.getUserInfo() != null) {
-            return new URIBuilder(uri).setFragment(null).setUserInfo(null).build();
+        if (uri.getFragment() != null || uri.getUserInfo() != null
+                || (uri.getPath() == null || uri.getPath().length() == 0)) {
+            URIBuilder uribuilder = new URIBuilder(uri);
+            uribuilder.setFragment(null).setUserInfo(null);
+            if (uribuilder.getPath() == null || uribuilder.getPath().length() == 0) {
+                uribuilder.setPath("/");
+            }
+            return uribuilder.build();
         } else {
             return uri;
         }

Modified: httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java?rev=1430006&r1=1430005&r2=1430006&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java
(original)
+++ httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/client/utils/TestURIUtils.java
Mon Jan  7 21:06:03 2013
@@ -54,6 +54,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(
@@ -62,6 +66,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



Mime
View raw message