Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
4.4 Final, 4.4.1, 4.5
Description
I recently upgraded my httpclient from 4.3.5 to 4.5 and noticed a difference in behavior in RequestBuilder.
Example.java
@Test public void testUrlParams() { URI uri1 = URI.create("http://host1.com/path?param=something"); URI uri2 = URI.create("http://host2.com/path?param=somethingdifferent"); HttpRequest getRequest = new HttpGet(uri1); HttpUriRequest uriRequest = RequestBuilder.copy(getRequest).setUri(uri2).build(); Assert.assertEquals(uriRequest.getURI(), uri2); } // Output: // java.lang.AssertionError: expected [http://host2.com/path?param=somethingdifferent] but found [http://host2.com/path?param=somethingdifferent¶m=something]
I had expected the setUri(...) to completely overwrite the URI of the copied request, but the URL parameters from the copied request were also appended to the resulting request URI. This is different than how it behaves in 4.3.5.
Looking at version 4.5 of RequestBuilder, the reason why this happens is that the parameters are extracted from the URI in line 305. They are then set on line 488 when the resulting request is built, regardless of whether the set URI already has parameters.
Is this working as intended?