lostisland / faraday

Simple, but flexible HTTP client library, with support for multiple backends.
https://lostisland.github.io/faraday
MIT License
5.72k stars 972 forks source link

Query parameters doesn't respect hash #1429

Closed sdalu closed 2 years ago

sdalu commented 2 years ago

Basic Info

Issue description

When performing a GET request with query parameters, the parameters seems to be re-ordered in alphabetical order. Which is an issue as some web site doesn't parse all parameters at once and behavior will differ due to parameter ordering

Steps to reproduce

Faraday.get('http://httpbin.org/get', :b => 1, :a => 1)

Anwser show that the request was: http://httpbin.org/get?a=1&b=1 Instead of expected: : http://httpbin.org/get?b=1&a=1

iMacTia commented 2 years ago

I'm sorry @sdalu I must have missed your issue and I just saw it! That is the default behaviour which is really useful for caching, but if for whatever reason you need to control the parameters order, you can disable that on the ParamEncoder you're using:

# NestedParamsEncoder is the default
Faraday::NestedParamsEncoder.sort_params = false
# or if you're using FlatParamsEncoder
Faraday::FlatParamsEncoder.sort_params = false
iMacTia commented 2 years ago

Actually let me keep this open, I just realised this is not documented on the website so I'd like to add it 🙌 !