hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1427487 - in /httpcomponents/httpclient/branches/4.2.x: ./ httpclient/src/main/java/org/apache/http/impl/client/ httpclient/src/test/java/org/apache/http/impl/client/
Date Tue, 01 Jan 2013 17:29:18 GMT
Author: olegk
Date: Tue Jan  1 17:29:18 2013
New Revision: 1427487

URL: http://svn.apache.org/viewvc?rev=1427487&view=rev
Log:
HTTPCLIENT-1286: Request URI rewriting is inconsistent - URI fragments are not removed from
absolute request URIs.

Modified:
    httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt
    httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
    httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.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=1427487&r1=1427486&r2=1427487&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt Tue Jan  1 17:29:18 2013
@@ -1,6 +1,10 @@
 Changes since 4.2.2
 -------------------
 
+* [HTTPCLIENT-1286] Request URI rewriting is inconsistent - URI fragments are not removed

+  from absolute request URIs.  
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPCLIENT-1284] HttpClient incorrectly generates Host header when physical connection
   route differs from the host name specified in the request URI. 
   Contributed by Oleg Kalnichevski <olegk at apache.org>

Modified: httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java?rev=1427487&r1=1427486&r2=1427487&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
(original)
+++ httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
Tue Jan  1 17:29:18 2013
@@ -386,7 +386,7 @@ public class DefaultRequestDirector impl
             } else {
                 // Make sure the request URI is relative
                 if (uri.isAbsolute()) {
-                    uri = URIUtils.rewriteURI(uri, null);
+                    uri = URIUtils.rewriteURI(uri, null, true);
                 } else {
                     uri = URIUtils.rewriteURI(uri);
                 }
@@ -1090,7 +1090,7 @@ public class DefaultRequestDirector impl
                 }
             }
         }
-        
+
         if (HttpClientParams.isRedirecting(params) &&
                 this.redirectStrategy.isRedirected(request, response, context)) {
 

Modified: httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java?rev=1427487&r1=1427486&r2=1427487&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java
(original)
+++ httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java
Tue Jan  1 17:29:18 2013
@@ -27,6 +27,7 @@ package org.apache.http.impl.client;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.net.URI;
 
 import org.apache.http.Header;
 import org.apache.http.HttpClientConnection;
@@ -42,6 +43,7 @@ import org.apache.http.client.NonRepeata
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.client.params.ClientPNames;
+import org.apache.http.client.utils.URIBuilder;
 import org.apache.http.entity.InputStreamEntity;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.localserver.BasicServerTestBase;
@@ -359,4 +361,44 @@ public class TestDefaultClientRequestDir
         }
     }
 
+    @Test
+    public void testRelativeRequestURIWithFragment() throws Exception {
+        this.localServer.register("*", new SimpleService());
+        HttpHost target = getServerHttp();
+
+        HttpGet httpget = new HttpGet("/stuff#blahblah");
+        HttpContext context = new BasicHttpContext();
+
+        HttpResponse response = this.httpclient.execute(target, httpget, context);
+        Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
+        EntityUtils.consume(response.getEntity());
+
+        HttpRequest request = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
+        Assert.assertEquals("/stuff", request.getRequestLine().getUri());
+    }
+
+    @Test
+    public void testAbsoluteRequestURIWithFragment() throws Exception {
+        this.localServer.register("*", new SimpleService());
+        HttpHost target = getServerHttp();
+
+        URI uri = new URIBuilder()
+            .setHost(target.getHostName())
+            .setPort(target.getPort())
+            .setScheme(target.getSchemeName())
+            .setPath("/stuff")
+            .setFragment("blahblah")
+            .build();
+
+        HttpGet httpget = new HttpGet(uri);
+        HttpContext context = new BasicHttpContext();
+
+        HttpResponse response = this.httpclient.execute(httpget, context);
+        Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
+        EntityUtils.consume(response.getEntity());
+
+        HttpRequest request = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
+        Assert.assertEquals("/stuff", request.getRequestLine().getUri());
+    }
+
 }



Mime
View raw message