Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for socks5 user and pass parameters. #323

Merged
merged 3 commits into from
Apr 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/httpoison/base.ex
Original file line number Diff line number Diff line change
Expand Up @@ -440,12 +440,20 @@ defmodule HTTPoison.Base do
end

proxy_auth = Keyword.get(options, :proxy_auth)
socks5_user = Keyword.get(options, :socks5_user)
socks5_pass = Keyword.get(options, :socks5_pass)

hn_proxy_options = if proxy, do: [{:proxy, proxy}], else: []

hn_proxy_options =
if proxy_auth, do: [{:proxy_auth, proxy_auth} | hn_proxy_options], else: hn_proxy_options

hn_proxy_options =
if socks5_user, do: [{:socks5_user, socks5_user} | hn_proxy_options], else: hn_proxy_options

hn_proxy_options =
if socks5_pass, do: [{:socks5_pass, socks5_pass} | hn_proxy_options], else: hn_proxy_options

hn_proxy_options
end

Expand Down
19 changes: 19 additions & 0 deletions test/httpoison_base_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,25 @@ defmodule HTTPoisonBaseTest do
assert validate :hackney
end

test "passing socks5 options" do
expect(:hackney, :request, [{
[:post, "http://localhost", [], "body", [
socks5_pass: "secret",
socks5_user: "user",
proxy: {:socks5, 'localhost', 1080}
]],
{:ok, 200, "headers", :client}}])
expect(:hackney, :body, 1, {:ok, "response"})

assert HTTPoison.post!("localhost", "body", [], proxy: {:socks5, 'localhost', 1080}, socks5_user: "user", socks5_pass: "secret") ==
%HTTPoison.Response{ status_code: 200,
headers: "headers",
body: "response",
request_url: "http://localhost" }

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}}])
Expand Down