Skip to content

Instantly share code, notes, and snippets.

@obfusk
Last active August 30, 2018 15:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save obfusk/bc146e6c76996792af859096cd37b4d6 to your computer and use it in GitHub Desktop.
Save obfusk/bc146e6c76996792af859096cd37b4d6 to your computer and use it in GitHub Desktop.
tiny elixir HTTP GET client w/ ssl verification using python3-certifi's certificate bundle
#!/usr/bin/elixir
defmodule HTTPGetter do
@cert '/usr/lib/python3/dist-packages/certifi/cacert.pem'
@opts [ ssl: [ verify: :verify_peer, cacertfile: @cert ] ]
def die msg do
IO.puts :stderr, msg; exit { :shutdown, 1 }
end
def get url do
case :httpc.request :get, { String.to_charlist(url), [] }, @opts, [] do
{ :ok, { { _v, 200, _m }, _h, body } } -> :erlang.list_to_binary body
{ :error, e } -> die "Error: #{inspect e}"
end
end
def main [url] do
:ssl.start; :inets.start; get(url) |> IO.write
end
def main(_), do: die "Usage: get.exs <url>"
end
HTTPGetter.main System.argv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment