Skip to content

Commit

Permalink
Merge pull request #71 from TicketRack/proxy_auth_param
Browse files Browse the repository at this point in the history
Accept proxy_auth parameter for hackney library
  • Loading branch information
edgurgel committed Sep 2, 2015
2 parents fb0daee + d356e7f commit 1da173b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/httpoison/base.ex
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,15 @@ defmodule HTTPoison.Base do
recv_timeout = Keyword.get options, :recv_timeout
stream_to = Keyword.get options, :stream_to
proxy = Keyword.get options, :proxy
proxy_auth = Keyword.get options, :proxy_auth

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 stream_to do
hn_options = [:async, {:stream_to, spawn(__MODULE__, :transformer, [stream_to])} | hn_options]
end
Expand Down
13 changes: 13 additions & 0 deletions test/httpoison_base_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,17 @@ defmodule HTTPoisonBaseTest do

assert validate :hackney
end

test "passing proxy option with proxy_auth" do
expect(:hackney, :request, [{[:post, "http://localhost", [], "body", [proxy_auth: {"username", "password"}, proxy: "proxy"]],
{:ok, 200, "headers", :client}}])
expect(:hackney, :body, 1, {:ok, "response"})

assert HTTPoison.post!("localhost", "body", [], [proxy: "proxy", proxy_auth: {"username", "password"}]) ==
%HTTPoison.Response{ status_code: 200,
headers: "headers",
body: "response" }

assert validate :hackney
end
end

0 comments on commit 1da173b

Please sign in to comment.