Skip to content

Commit

Permalink
Merge pull request bblimke#313 from burns/excon_params
Browse files Browse the repository at this point in the history
scrub invalid request params for Excon
  • Loading branch information
bblimke committed Oct 15, 2013
2 parents 327b2df + 9d87a2c commit 3b9efc0
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/webmock/http_lib_adapters/excon_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
end

if defined?(Excon)
WebMock::VersionChecker.new('Excon', Excon::VERSION, '0.22.0').check_version!
WebMock::VersionChecker.new('Excon', Excon::VERSION, '0.27.5').check_version!

module WebMock
module HttpLibAdapters
Expand Down Expand Up @@ -54,7 +54,7 @@ def self.handle_request(params)
response
elsif WebMock.net_connect_allowed?(mock_request.uri)
conn = new_excon_connection(params)
real_response = conn.request(scrub_params_from(params.merge(:mock => false)))
real_response = conn.request(request_params_from(params.merge(:mock => false)))

ExconAdapter.perform_callbacks(mock_request, ExconAdapter.mock_response(real_response), :real_request => true)

Expand All @@ -68,15 +68,25 @@ def self.new_excon_connection(params)
# Ensure the connection is constructed with the exact same args
# that the orginal connection was constructed with.
args = params.fetch(:__construction_args)
::Excon::Connection.new(scrub_params_from args.merge(:mock => false))
::Excon::Connection.new(connection_params_from args.merge(:mock => false))
end

def self.scrub_params_from(hash)
def self.connection_params_from(hash)
hash = hash.dup
PARAMS_TO_DELETE.each { |key| hash.delete(key) }
hash
end

def self.request_params_from(hash)
hash = hash.dup
if Excon::VERSION >= '0.27.5'
request_keys = Excon::Utils.valid_request_keys(hash)
hash.reject! {|key,_| !request_keys.include?(key) }
end
PARAMS_TO_DELETE.each { |key| hash.delete(key) }
hash
end

def self.to_query(hash)
string = ""
for key, values in hash
Expand Down

0 comments on commit 3b9efc0

Please sign in to comment.