Skip to content

Instantly share code, notes, and snippets.

@orenbenkiki
Created February 23, 2013 05:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orenbenkiki/5018601 to your computer and use it in GitHub Desktop.
Save orenbenkiki/5018601 to your computer and use it in GitHub Desktop.
Patch expm http.ex to pass http proxy settings to hackney
diff --git a/lib/repositories/http.ex b/lib/repositories/http.ex
index 2dae690..bdb1ece 100644
--- a/lib/repositories/http.ex
+++ b/lib/repositories/http.ex
@@ -9,7 +9,7 @@ defrecord Expm.Repository.HTTP, url: "https://expm.co", username: nil, password:
{"accept", "text/html"},
{"user-agent", "expm/#{Expm.version}"},
],
- "", [follow_redirect: true, force_redirect: true])
+ "", Expm.Repository.HTTP.Decoder.proxy(follow_redirect: true, force_redirect: true))
{:ok, body, client} = H.body(client)
H.close(client)
body
@@ -21,6 +21,25 @@ end
defmodule Expm.Repository.HTTP.Decoder do
defexception SecurityException, message: nil
+ def proxy(options) do
+ case :os.getenv("https_proxy") do
+ false ->
+ case :os.getenv("HTTPS_PROXY") do
+ false ->
+ case :os.getenv("http_proxy") do
+ false ->
+ case :os.getenv("HTTP_PROXY") do
+ false -> options
+ proxy -> [ { :proxy, proxy } | options ]
+ end
+ proxy -> [ { :proxy, proxy } | options ]
+ end
+ proxy -> [ { :proxy, proxy } | options ]
+ end
+ proxy -> [ { :proxy, proxy } | options ]
+ end
+ end
+
def decode({ :__block__, _, [b] }) when is_list(b) do
decode_1(b)
end
@@ -59,7 +78,7 @@ defimpl Expm.Repository, for: Expm.Repository.HTTP do
{"accept", "application/elixir"},
{"user-agent", "expm/#{Expm.version}"},
],
- "", [follow_redirect: true, force_redirect: true])
+ "", Expm.Repository.HTTP.Decoder.proxy(follow_redirect: true, force_redirect: true))
{:ok, body, client} = H.body(client)
H.close(client)
case code do
@@ -77,7 +96,7 @@ defimpl Expm.Repository, for: Expm.Repository.HTTP do
{"accept", "application/elixir"},
{"user-agent", "expm/#{Expm.version}"},
],
- "", [follow_redirect: true, force_redirect: true])
+ "", Expm.Repository.HTTP.Decoder.proxy(follow_redirect: true, force_redirect: true))
{:ok, body, client} = H.body(client)
H.close(client)
case code do
@@ -102,7 +121,7 @@ defimpl Expm.Repository, for: Expm.Repository.HTTP do
{"accept", "application/elixir"},
{"user-agent", "expm/#{Expm.version}"},
],
- spec.encode, [follow_redirect: true, force_redirect: true])
+ spec.encode, Expm.Repository.HTTP.Decoder.proxy(follow_redirect: true, force_redirect: true))
{:ok, body, client} = H.body(client)
H.close(client)
case code do
@@ -120,7 +139,7 @@ defimpl Expm.Repository, for: Expm.Repository.HTTP do
{"accept", "application/elixir"},
{"user-agent", "expm/#{Expm.version}"},
],
- "", [follow_redirect: true, force_redirect: true])
+ "", Expm.Repository.HTTP.Decoder.proxy(follow_redirect: true, force_redirect: true))
{:ok, body, client} = H.body(client)
H.close(client)
case code do
@@ -138,7 +157,7 @@ defimpl Expm.Repository, for: Expm.Repository.HTTP do
{"accept", "application/elixir"},
{"user-agent", "expm/#{Expm.version}"},
],
- filter.encode, [follow_redirect: true, force_redirect: true])
+ filter.encode, Expm.Repository.HTTP.Decoder.proxy(follow_redirect: true, force_redirect: true))
{:ok, body, client} = H.body(client)
H.close(client)
case code do
@@ -149,4 +168,4 @@ defimpl Expm.Repository, for: Expm.Repository.HTTP do
end
end
-end
\ No newline at end of file
+end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment