[
https://issues.apache.org/jira/browse/HTTPCLIENT-1916?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Oleg Kalnichevski resolved HTTPCLIENT-1916.
-------------------------------------------
Resolution: Won't Fix
Fix Version/s: (was: Stuck)
> 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: 4.5.5, 4.5.6, 5.0 Beta1, 5.0 Beta2
> Reporter: Jorge Moraleda
> Priority: Trivial
> Labels: features, stuck, volunteers-wanted
> Original Estimate: 0.5h
> Remaining Estimate: 0.5h
>
> It would be convenient to have a *removeParameter* method added to class
> *URIBuilder*.
> One rationale for this proposal is the use case when of 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 would be the implementation of the proposed method *removeParameter*:
> {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 new parameter, then
> the implementation of *setParameter* could be simplified greatly to:
>
> {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);
> if (this.queryParams == null) {
> this.queryParams = new ArrayList<NameValuePair>();
> }
> this.queryParams.add(new BasicNameValuePair(param, value));
> return this;
> }
> {code}
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]