Skip to content

Commit

Permalink
Handling headers passed as an array in Curb.
Browse files Browse the repository at this point in the history
  • Loading branch information
bblimke committed May 20, 2016
1 parent 9358da3 commit 8f2f28b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/webmock/http_lib_adapters/curb_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,23 @@ def build_request_signature
method,
uri.to_s,
:body => request_body,
:headers => self.headers.merge(basic_auth_headers)
:headers => headers_as_hash(self.headers).merge(basic_auth_headers)
)
request_signature
end

def headers_as_hash(headers)
if headers.is_a?(Array)
headers.inject({}) {|hash, header|
name, value = header.split(":").map(&:strip)
hash[name] = value
hash
}
else
headers
end
end

def basic_auth_headers
if self.username
{'Authorization' => WebMock::Util::Headers.basic_auth_header(self.username, self.password)}
Expand Down
10 changes: 10 additions & 0 deletions spec/acceptance/curb/curb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,16 @@
c.http(:GET)
expect(c.body).to eq("abc")
end

it "supports array headers passed to Curl::Easy" do
stub_request(:get, "www.example.com").with(headers: {'X-One' => '1'}).to_return(:body => "abc")

c = Curl::Easy.new
c.url = "http://www.example.com"
c.headers = ["X-One: 1"]
c.http(:GET)
expect(c.body).to eq("abc")
end
end

describe "using #http_* methods for requests" do
Expand Down

0 comments on commit 8f2f28b

Please sign in to comment.