-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not possible to use array-syntax for query string params #28
Comments
HttpGetWithEntity should be just a GET, except that it'll accept an entity body. If you don't pass a body/entity param, it'll just behave as an RFC-compliant GET. I would prefer RFC compliance, but there were several early examples of practical use cases with GETs-with-bodies being necessary (Elasticsearch primarily), and a survey of other Ruby HTTP clients showed that they tended to pass entity bodies, so I elected for practical compliance over RFC adherence. Is it actually breaking something for you, or what's sparking the concern? I'll investigate what's up with the hash collisions; the array syntax should definitely be properly supported. |
Thanks for the quick response @cheald. The behavior I see of |
Oh, I see - you're using Using this spec to test with:
You get this wire output:
I think the correct fix is to probably just treat |
OK @cheald I just found the |
This is what I just found too. Thanks a lot @cheald. I think maybe just an example in the README with |
Manticore uses the I'll get the doc updated at a minimum, and see if there are other things I can do to make it more clear. Thanks! |
4353034 should smooth over these issues nicely. Feel free to re-open this ticket if you find anything else not-quite-right with it! |
Thanks for the quick turnaround @cheald. However, I this is still not generating the e.g. Manticore.get(url, params: { 'foo' => ['bar', 'baz'] }).body Is generating this URL:
When received by Rails then the params hash simply has { foo: 'baz' }. Here is the change we made that seems to make this work: def struct_to_name_value_pairs(value, namespace = nil)
case value
when nil
[]
when Hash
value.flat_map {|key, val| struct_to_name_value_pairs val, namespace ? "#{namespace}[#{key}]" : key }
when Array
value.flat_map {|val| struct_to_name_value_pairs val, "#{namespace}[]" } # This is the changed line
else
BasicNameValuePair.new(namespace, value.to_s)
end
end |
Yeah, that's the issue that I was referring to WRT Addressable; it was in at one point, and then rolled back for greater compatibility. The Ruby CGI module, for example, interprets each of these as:
I think that for the time being, I'd suggest that if you want to pass an array of values with []-style multi-value deliniation, I'd recommend:
|
@cheald Yep, we just finished hypothesizing and testing that ourselves. That seems reasonable to me. Thanks again! |
Expected behavior (with CURL):
Received by server: http://requestb.in/1d2oe0t1?inspect#1mtdlx
The server received foo[]: 'bar' and foo[]:: 'baz' (as query string params).
Incorrect behavior (Manticore):
Received by server: http://requestb.in/1d2oe0t1?inspect#ts3ow1
As you can see, this was received only as a body, and the
foo[] => 'bar'
param was overwritten by the 'baz' param.Also, is there a way to bypass the use of
HttpGetWithEntity
and use a regular RFC-2616 compliant GET request? Perhaps theGetWithEntity
should be explicitly configurable?Thanks!
update
Perhaps the
hash_to_entity
(assuming we're stuck with using a GET with an entity) should support a regular Ruby Array as the value of a query param and did the conversion on its own. We tried the following, but it exhibited the same behavior as the example above:The text was updated successfully, but these errors were encountered: