fix bug with array into params
array colors['red', 'green'] must convert to
colors[]=red&colors[]=green but not colors=red&colors=green
Hiroshi Nakamura » httpclient #86 FAILURE Looks like there's a problem with this pull request (what's this?)
@nahi What do you think about?
Is this a Rails convention, right? I'm open to add this as a new feature but I don't want to break existing application.
right, here is to params convert sample https://gist.github.com/achempion/7750548 into rails console
I have a trouble with fix specs for changes
As far as I know, there is no "right answer" for it.
if Rails gets query params encoded as "foo=x&foo=y" then in the end randomly (well randomness in this case may mean always last value, but haven't checked) results:
{
foo: 'y'
}
which is clearly inapproriate.
So currently params must be manually encoded (aka. "params.to_query") if using Rails as backend server.
This naturally means that default behavior of HTTPClient is broken with Rails. Note that this is also inconsistent with default behavior of "rest-client" gem (common simple REST client), which may cause surprise when switching to HTTPClient.
When fixing this, please also consider addressing "null value" encoding, so that null value doesn't convert into empty string. In Rails, if query param is passed in as "foo" then it is interpreted as nil, while "foo=" comes out as empty string.
Of course using "application/json" encoding in body avoids problem, but for GET calls that option is naturally not available.
Surely could just document well, that one must use "params.to_query" if wanting this possibly Rails specific encoding convention (especially since "to_query" will also manage Rails specific logic for encoding nested map structures).
I think that we can resolve this just added a configuration file with setting called like "query_params_pattern"
Adding option sounds nice.