httpclient icon indicating copy to clipboard operation
httpclient copied to clipboard

fix bug with array into params

Open achempion opened this issue 12 years ago • 8 comments

array colors['red', 'green'] must convert to colors[]=red&colors[]=green but not colors=red&colors=green

achempion avatar Nov 07 '13 11:11 achempion

Hiroshi Nakamura » httpclient #86 FAILURE Looks like there's a problem with this pull request (what's this?)

buildhive avatar Nov 07 '13 11:11 buildhive

@nahi What do you think about?

achempion avatar Nov 07 '13 11:11 achempion

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.

nahi avatar Dec 02 '13 13:12 nahi

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

achempion avatar Dec 02 '13 14:12 achempion

As far as I know, there is no "right answer" for it.

chulkilee avatar Jun 28 '14 00:06 chulkilee

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).

kikonen-fiksu avatar Oct 23 '14 17:10 kikonen-fiksu

I think that we can resolve this just added a configuration file with setting called like "query_params_pattern"

achempion avatar Oct 24 '14 09:10 achempion

Adding option sounds nice.

nahi avatar Nov 03 '14 07:11 nahi