edgurgel / httpoison

Yet Another HTTP client for Elixir powered by hackney
https://hex.pm/packages/httpoison
MIT License
2.22k stars 339 forks source link

Conditionally process `:form` bodies to handle nested params #470

Closed vereis closed 1 year ago

vereis commented 1 year ago

Ahoy again!

This PR is larger than I expected because when I was looking at the HTTPoison source when I made my issue, I didn't realise I was only looking at the to_curl function :disappointed:, so apologies if this is bigger than expected.

When {:form, body} is passed as a body into HTTPoison, we iterate over all the keys in said body and iff a key contains a nested keyword-list, we apply the following transformation:

[something_nested: [hello: :world]] -> [{"something_nested[hello]", :world}]

The function added supports arbitrarily deeply nested params, and should preserve the order in which things are passed in.

@edgurgel do you think we should extend this to support maps as well? It should be relatively minor (a change in the pattern matches) but then we'd throw the key-ordering guarantees away. WDYT? _edit: Added a second commit that adds support for maps__

Should fix https://github.com/edgurgel/httpoison/issues/469

edgurgel commented 1 year ago

Thanks for the PR! I will definitely check it out later this week

edgurgel commented 1 year ago

Thanks! I will cut a new release soon :soon: