hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1685284 - in /httpcomponents/httpclient/trunk/httpclient/src: main/java/org/apache/http/client/methods/RequestBuilder.java test/java/org/apache/http/client/methods/TestRequestBuilder.java
Date Sat, 13 Jun 2015 16:30:56 GMT
Author: olegk
Date: Sat Jun 13 16:30:56 2015
New Revision: 1685284

URL: http://svn.apache.org/r1685284
Log:
HTTPCLIENT-1658: fixed regression in RequestBuilder#copy

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/RequestBuilder.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/methods/TestRequestBuilder.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/RequestBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/RequestBuilder.java?rev=1685284&r1=1685283&r2=1685284&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/RequestBuilder.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/methods/RequestBuilder.java
Sat Jun 13 16:30:56 2015
@@ -293,26 +293,9 @@ public class RequestBuilder {
 
         final URI originalUri;
         if (request instanceof HttpUriRequest) {
-            originalUri = ((HttpUriRequest) request).getURI();
+            uri = ((HttpUriRequest) request).getURI();
         } else {
-            originalUri = URI.create(request.getRequestLine().getUri());
-        }
-
-        final URIBuilder uriBuilder = new URIBuilder(originalUri);
-        if (parameters == null) {
-            final List<NameValuePair> queryParams = uriBuilder.getQueryParams();
-            if (!queryParams.isEmpty()) {
-                parameters = queryParams;
-                uriBuilder.clearParameters();
-            } else {
-                parameters = null;
-            }
-        }
-        try {
-            uri = uriBuilder.build();
-        } catch (URISyntaxException ex) {
-            // Should never happen
-            uri = originalUri;
+            uri = URI.create(request.getRequestLine().getUri());
         }
 
         if (request instanceof Configurable) {

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/methods/TestRequestBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/methods/TestRequestBuilder.java?rev=1685284&r1=1685283&r2=1685284&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/methods/TestRequestBuilder.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/methods/TestRequestBuilder.java
Sat Jun 13 16:30:56 2015
@@ -33,6 +33,7 @@ import java.util.List;
 import org.apache.http.Header;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.HttpRequest;
 import org.apache.http.HttpVersion;
 import org.apache.http.NameValuePair;
 import org.apache.http.client.config.RequestConfig;
@@ -168,10 +169,8 @@ public class TestRequestBuilder {
         final RequestBuilder builder = RequestBuilder.copy(get);
         final List<NameValuePair> parameters = builder.getParameters();
         Assert.assertNotNull(parameters);
-        Assert.assertEquals(2, parameters.size());
-        Assert.assertEquals(new BasicNameValuePair("p1", "this"), parameters.get(0));
-        Assert.assertEquals(new BasicNameValuePair("p2", "that"), parameters.get(1));
-        Assert.assertEquals(new URI("/stuff"), builder.getUri());
+        Assert.assertEquals(0, parameters.size());
+        Assert.assertEquals(new URI("/stuff?p1=this&p2=that"), builder.getUri());
     }
 
     @Test
@@ -196,13 +195,21 @@ public class TestRequestBuilder {
         final RequestBuilder builder = RequestBuilder.copy(post);
         final List<NameValuePair> parameters = builder.getParameters();
         Assert.assertNotNull(parameters);
-        Assert.assertEquals(1, parameters.size());
-        Assert.assertEquals(new BasicNameValuePair("p1", "wtf"), parameters.get(0));
-        Assert.assertEquals(new URI("/stuff"), builder.getUri());
+        Assert.assertEquals(0, parameters.size());
+        Assert.assertEquals(new URI("/stuff?p1=wtf"), builder.getUri());
         Assert.assertSame(entity, builder.getEntity());
     }
 
     @Test
+    public void testCopyAndSetUri() throws Exception {
+        final URI uri1 = URI.create("http://host1.com/path?param=something");
+        final URI uri2 = URI.create("http://host2.com/path?param=somethingdifferent");
+        final HttpRequest request1 = new HttpGet(uri1);
+        final HttpUriRequest request2 = RequestBuilder.copy(request1).setUri(uri2).build();
+        Assert.assertEquals(request2.getURI(), uri2);
+    }
+
+    @Test
     public void testGettersAndMutators() throws Exception {
         final HttpEntity entity = new StringEntity("stuff");
         final RequestConfig config = RequestConfig.custom().build();



Mime
View raw message