Skip to content

Commit 497fe60

Browse files
committed
http proxy updates
1 parent 4c54422 commit 497fe60

File tree

6 files changed

+23
-8
lines changed

6 files changed

+23
-8
lines changed

apps/http_proxy/config/config.exs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
# and its dependencies with the aid of the Mix.Config module.
33
use Mix.Config
44

5-
config :out_proxy, :redirect_to_tor, false
5+
config :http_proxy, :redirect_to_tor, false
6+
7+
config :http_proxy, :http_listen_port, System.get_env("HTTP_PROXY_PORT") || 4480

apps/http_proxy/lib/http_proxy/cache_lookup.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ defmodule HttpProxy.CacheLookup do
7272
end
7373

7474
conn
75-
|> HttpProxy.HttpHandler.forward_response(conn)
75+
|> HttpProxy.HttpHandler.forward_response
7676
|> halt
7777
end
7878
end

apps/http_proxy/lib/http_proxy/endpoint.ex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ defmodule HttpProxy.Endpoint do
2222
def init(opts), do: opts
2323

2424
def start_link do
25-
# port = Application.get_env :out_proxy, :port
26-
port = 4480
25+
port = Application.get_env(:http_proxy, :http_listen_port)
26+
:ok = :hackney_pool.start_pool(:httpc_pool, [
27+
timeout: 15_000,
28+
max_connections: 1_000
29+
])
2730
Logger.info("Running #{__MODULE__} on port #{port}")
2831
{:ok, _} = Plug.Adapters.Cowboy.http(__MODULE__, [], port: port)
2932
end

apps/http_proxy/lib/http_proxy/http_handler.ex

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,16 @@ defmodule HttpProxy.HttpHandler do
1919
# if not - the forwarding crashes and burns, might eat your childs as well.
2020
headers = Keyword.drop(conn.assigns.headers, ["host","proxy-connection"])
2121

22-
req_options = [follow_redirect: true, hackney: [force_redirect: true]]
23-
if Application.get_env(:out_proxy, :redirect_to_tor, false) do
22+
req_options = [
23+
follow_redirect: true,
24+
hackney: [
25+
pool: :httpc_pool
26+
],
27+
max_redirect: 7,
28+
recv_timeout: 10_000,
29+
timeout: 12_000,
30+
]
31+
if Application.get_env(:http_proxy, :redirect_to_tor, false) do
2432
do_request(conn, method, url, body, headers, req_options ++ [proxy: {:socks5, "127.0.0.1", 9050}])
2533
else
2634
do_request(conn, method, url, body, headers, req_options)

apps/http_proxy/lib/http_proxy/https_handler.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ defmodule HttpProxy.HttpsHandler do
2626

2727
defp open_remote_connection(conn) do
2828
[bin_host, port] = String.split(conn.request_path, ":")
29-
host = String.to_char_list(bin_host)
29+
host = String.to_charlist(bin_host)
3030
port = String.to_integer(port)
3131

3232
{status, sock} = case :gen_tcp.connect(host, port, [:binary, active: false]) do

apps/http_proxy/mix.exs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ defmodule HttpProxy.Mixfile do
2525
:logger,
2626
:cowboy,
2727
:plug,
28-
:httpoison
28+
:httpoison,
29+
:dns
2930
],
3031
mod: {HttpProxy, []}
3132
]
@@ -50,6 +51,7 @@ defmodule HttpProxy.Mixfile do
5051
{:plug_cowboy, "~> 1.0"},
5152
{:plug, "~> 1.8"},
5253
{:httpoison, "~> 1.5.1"},
54+
{:dns, "~> 2.1.2"},
5355
]
5456
end
5557
end

0 commit comments

Comments
 (0)