hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1427482 - in /httpcomponents/httpclient/trunk: ./ httpclient/src/main/java/org/apache/http/impl/client/ httpclient/src/main/java/org/apache/http/impl/client/execchain/ httpclient/src/test/java/org/apache/http/impl/client/integration/
Date Tue, 01 Jan 2013 17:26:09 GMT
Author: olegk
Date: Tue Jan  1 17:26:08 2013
New Revision: 1427482

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

Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/ProtocolExec.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=1427482&r1=1427481&r2=1427482&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Tue Jan  1 17:26:08 2013
@@ -8,6 +8,10 @@ Changes in trunk
   responses.
   Contributed by Don Brown <mrdon at twdata.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>
+
 * [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/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java?rev=1427482&r1=1427481&r2=1427482&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
Tue Jan  1 17:26:08 2013
@@ -351,7 +351,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);
                 }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/ProtocolExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/ProtocolExec.java?rev=1427482&r1=1427481&r2=1427482&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/ProtocolExec.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/execchain/ProtocolExec.java
Tue Jan  1 17:26:08 2013
@@ -93,7 +93,7 @@ public class ProtocolExec implements Cli
                 } 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);
                     }

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java?rev=1427482&r1=1427481&r2=1427482&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestClientRequestExecution.java
Tue Jan  1 17:26:08 2013
@@ -28,10 +28,12 @@ package org.apache.http.impl.client.inte
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.net.URI;
 
 import org.apache.http.Header;
 import org.apache.http.HttpClientConnection;
 import org.apache.http.HttpException;
+import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpRequestInterceptor;
 import org.apache.http.HttpResponse;
@@ -41,6 +43,7 @@ import org.apache.http.client.HttpReques
 import org.apache.http.client.NonRepeatableRequestException;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.utils.URIBuilder;
 import org.apache.http.entity.InputStreamEntity;
 import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.HttpClients;
@@ -217,4 +220,46 @@ public class TestClientRequestExecution 
         Assert.assertEquals("blah.:.blah.:.", reqWrapper.getRequestLine().getUri());
     }
 
+    @Test
+    public void testRelativeRequestURIWithFragment() throws Exception {
+        this.localServer.register("*", new SimpleService());
+        this.httpclient = HttpClients.createDefault();
+        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());
+        this.httpclient = HttpClients.createDefault();
+        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