Kevin Fongson created HTTPCLIENT-1658:
-----------------------------------------
Summary: Possible incorrect interaction in
RequestBuilder.copy(...) and setURI(...)
Key: HTTPCLIENT-1658
URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1658
Project: HttpComponents HttpClient
Issue Type: Bug
Components: HttpClient
Affects Versions: 4.5, 4.4.1, 4.4 Final
Reporter: Kevin Fongson
Priority: Minor
I recently upgraded my httpclient from 4.3.5 to 4.5 and noticed a difference in
behavior in RequestBuilder.
{code:title=Example.java|borderStyle=solid}
@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]
{code}
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?
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]