Skip to content

Commit

Permalink
Add ssl option to request calls
Browse files Browse the repository at this point in the history
  • Loading branch information
edgurgel committed Sep 21, 2015
1 parent 77255b2 commit 2637f66
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/httpoison/base.ex
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,15 @@ defmodule HTTPoison.Base do
stream_to = Keyword.get options, :stream_to
proxy = Keyword.get options, :proxy
proxy_auth = Keyword.get options, :proxy_auth
ssl = Keyword.get options, :ssl

hn_options = Keyword.get options, :hackney, []

if timeout, do: hn_options = [{:connect_timeout, timeout} | hn_options]
if recv_timeout, do: hn_options = [{:recv_timeout, recv_timeout} | hn_options]
if proxy, do: hn_options = [{:proxy, proxy} | hn_options]
if proxy_auth, do: hn_options = [{:proxy_auth, proxy_auth} | hn_options]
if ssl, do: hn_options = [{:ssl_options, ssl} | hn_options]

if stream_to do
hn_options = [:async, {:stream_to, spawn(module, :transformer, [stream_to])} | hn_options]
Expand Down Expand Up @@ -392,5 +394,4 @@ defmodule HTTPoison.Base do
body: process_response_body.(body)
} }
end

end
13 changes: 13 additions & 0 deletions test/httpoison_base_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,17 @@ defmodule HTTPoisonBaseTest do

assert validate :hackney
end

test "passing ssl option" do
expect(:hackney, :request, [{[:post, "http://localhost", [], "body", [ssl_options: [certfile: "certs/client.crt"]]],
{:ok, 200, "headers", :client}}])
expect(:hackney, :body, 1, {:ok, "response"})

assert HTTPoison.post!("localhost", "body", [], ssl: [certfile: "certs/client.crt"]) ==
%HTTPoison.Response{ status_code: 200,
headers: "headers",
body: "response" }

assert validate :hackney
end
end
7 changes: 6 additions & 1 deletion test/httpoison_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ defmodule HTTPoisonTest do
end

test "https scheme" do
assert_response HTTPoison.head("https://localhost:8433/get", [], [ hackney: [:insecure]])
httparrot_priv_dir = :code.priv_dir(:httparrot)
cacert_file = "#{httparrot_priv_dir}/ssl/server-ca.crt"
cert_file = "#{httparrot_priv_dir}/ssl/server.crt"
key_file = "#{httparrot_priv_dir}/ssl/server.key"

assert_response HTTPoison.get("https://localhost:8433/get", [], ssl: [cacertfile: cacert_file, keyfile: key_file, certfile: cert_file])
end

test "char list URL" do
Expand Down

0 comments on commit 2637f66

Please sign in to comment.