Last active
August 30, 2018 15:41
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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