Skip to content
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

Add option to enable Rack-like encoding of array parameters #104

Merged
merged 9 commits into from
Jun 11, 2015
Merged

Add option to enable Rack-like encoding of array parameters #104

merged 9 commits into from
Jun 11, 2015

Conversation

vjt
Copy link
Contributor

@vjt vjt commented Jun 8, 2015

Rack applications expect

foo: ['bar', 'baz']

to be encoded as:

foo[]=bar&foo[]=baz

whilst Ethon by default encodes it as:

foo[0]=bar&foo[1]=baz

This patch adds an array_encoding option to Ethon::Easy. If it set to :rack, then arrays are encoded the Rack way, both in params: {} and in body: {}. Any other value retains the current behaviour.

The option can be forwarded directly from Typhoeus::Request.new.

This implements typhoeus/typhoeus#424.

# This is called here to have the side effect of removing
# the :array_encoding key from options, to avoid forwarding
# it to Curl later. FIXME.
array_encoding
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is indeed a bit hacky. Could you explicitly remove it in a separate step?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about the name params_encoding for the option?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll gladly refactor the Actionable initialization.

params_encoding looks good to me. Even though it only affects arrays, for now, it's more explanatory and forward-looking.

@vjt
Copy link
Contributor Author

vjt commented Jun 10, 2015

@i0rek all done. 😺

@hanshasselberg
Copy link
Member

Thank you very much for your work @vjt!

hanshasselberg added a commit that referenced this pull request Jun 11, 2015
Add option to enable Rack-like encoding of array parameters
@hanshasselberg hanshasselberg merged commit e0fc816 into typhoeus:master Jun 11, 2015
@vjt
Copy link
Contributor Author

vjt commented Jun 11, 2015

Thanks for the merge, @i0rek! My pleasure.

@radar
Copy link

radar commented Jun 30, 2015

Thanks @vjt for this fix :) This is exactly what I needed in my app.

@dblock
Copy link

dblock commented Feb 8, 2018

Been tracking this for a while, trying to get rid of a fork in our code, related links: #52
https://github.com/dylanfareed/ethon/commit/548033a8557a48203b7d49f3f98812bd79bc05e4
typhoeus/typhoeus#320

dblock referenced this pull request Feb 8, 2018
typhoeus/typhoeus#320

We were seeing array params tranformed into the following:
/event?groups[0]=open-forum&groups[1]=armory-films

but we need the client to send array params to various API
services in the following (valid) format:
/event?groups[]=open-forum&groups[]=armory-films
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants