hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin Fongson (JIRA)" <j...@apache.org>
Subject [jira] [Created] (HTTPCLIENT-1658) Possible incorrect interaction in RequestBuilder.copy(...) and setURI(...)
Date Fri, 12 Jun 2015 00:48:00 GMT
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

    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&param=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?

This message was sent by Atlassian JIRA

To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org

View raw message