You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Jorge Moraleda (JIRA)" <ji...@apache.org> on 2018/04/20 02:59:00 UTC

[jira] [Created] (HTTPCLIENT-1916) Add method removeParameter to URIBuilder

Jorge Moraleda created HTTPCLIENT-1916:
------------------------------------------

             Summary: Add method removeParameter to URIBuilder
                 Key: HTTPCLIENT-1916
                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1916
             Project: HttpComponents HttpClient
          Issue Type: New Feature
          Components: HttpClient (classic)
    Affects Versions: 5.0 Beta1, 4.5.5, 4.5.6, 5.0 Beta2
            Reporter: Jorge Moraleda


It would be convenient to have a *removeParameter* method added to class *URIBuilder*: This would be its implementation
{code:java}
    /**
     * Remove parameter of URI query if set. The parameter name
     * is expected to be unescaped and may contain non ASCII characters.
     * <p>
     * Please note query parameters and custom query component are mutually exclusive. This method
     * will remove custom query if present.
     * </p>
     */
    public URIBuilder removeParameter(final String param) {
        if (this.queryParams == null) {
            return this;
        }
        if (!this.queryParams.isEmpty()) {
            for (final Iterator<NameValuePair> it = this.queryParams.iterator(); it.hasNext(); ) {
                final NameValuePair nvp = it.next();
                if (nvp.getName().equals(param)) {
                    it.remove();
                }
            }
        }
        this.encodedQuery = null;
        this.encodedSchemeSpecificPart = null;
        this.query = null;
        return this;
   }
{code}
Since the proposed implementation above is the current implementation of *setParameter* minus the one line that actually adds the parameter, then the implementation of *setParameter* would become:

 
{code:java}
    /**
     * Sets parameter of URI query overriding existing value if set. The parameter name and value
     * are expected to be unescaped and may contain non ASCII characters.
     * <p>
     * Please note query parameters and custom query component are mutually exclusive. This method
     * will remove custom query if present.
     * </p>
     */
    public URIBuilder setParameter(final String param, final String value) {
        removeParameter(param);
        this.queryParams.add(new BasicNameValuePair(param, value));
        return this;
    }
{code}
The rationale for this proposal is the use case when when reusing an *URIBuilder* to create multiple similar HMAC signed requests. In that scenario it is not sufficient to invoke *setParameter* with the values of the parameters that have changed. One also needs to remove the _signature_ parameter from the previous request before the current request can be signed and a new _signature_ parameter added to it.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

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