mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-09 00:04:39 -04:00
Honour request.options.params_encoder
This commit is contained in:
parent
5bfa4bf948
commit
ad226f75ab
@ -396,7 +396,7 @@ module Faraday
|
|||||||
# of the resulting url (default: nil).
|
# of the resulting url (default: nil).
|
||||||
#
|
#
|
||||||
# Returns the resulting URI instance.
|
# Returns the resulting URI instance.
|
||||||
def build_exclusive_url(url = nil, params = nil)
|
def build_exclusive_url(url = nil, params = nil, params_encoder = nil)
|
||||||
url = nil if url.respond_to?(:empty?) and url.empty?
|
url = nil if url.respond_to?(:empty?) and url.empty?
|
||||||
base = url_prefix
|
base = url_prefix
|
||||||
if url and base.path and base.path !~ /\/$/
|
if url and base.path and base.path !~ /\/$/
|
||||||
@ -404,7 +404,7 @@ module Faraday
|
|||||||
base.path = base.path + '/' # ensure trailing slash
|
base.path = base.path + '/' # ensure trailing slash
|
||||||
end
|
end
|
||||||
uri = url ? base + url : base
|
uri = url ? base + url : base
|
||||||
uri.query = params.to_query(options.params_encoder) if params
|
uri.query = params.to_query(params_encoder || options.params_encoder) if params
|
||||||
uri.query = nil if uri.query and uri.query.empty?
|
uri.query = nil if uri.query and uri.query.empty?
|
||||||
uri
|
uri
|
||||||
end
|
end
|
||||||
|
@ -188,7 +188,7 @@ module Faraday
|
|||||||
# :ssl - Hash of options for configuring SSL requests.
|
# :ssl - Hash of options for configuring SSL requests.
|
||||||
def build_env(connection, request)
|
def build_env(connection, request)
|
||||||
Env.new(request.method, request.body,
|
Env.new(request.method, request.body,
|
||||||
connection.build_exclusive_url(request.path, request.params),
|
connection.build_exclusive_url(request.path, request.params, request.options.params_encoder),
|
||||||
request.options, request.headers, connection.ssl,
|
request.options, request.headers, connection.ssl,
|
||||||
connection.parallel_manager)
|
connection.parallel_manager)
|
||||||
end
|
end
|
||||||
|
@ -517,6 +517,24 @@ class TestRequestParams < Faraday::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class FooBarEncoder
|
||||||
|
def self.encode(params)
|
||||||
|
"foo=bar"
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.decode(param_string)
|
||||||
|
{"foo" => "bar"}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_params_with_connection_options
|
||||||
|
create_connection 'http://a.co/page1', :params => {:color => 'blue'}
|
||||||
|
query = get do |req|
|
||||||
|
req.options.params_encoder = FooBarEncoder
|
||||||
|
end
|
||||||
|
assert_equal "foo=bar", query
|
||||||
|
end
|
||||||
|
|
||||||
def get(*args)
|
def get(*args)
|
||||||
env = @conn.get(*args) do |req|
|
env = @conn.get(*args) do |req|
|
||||||
yield(req) if block_given?
|
yield(req) if block_given?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user