Skip to content

Instantly share code, notes, and snippets.

@dnet
Created February 9, 2012 12:28
Show Gist options
  • Save dnet/1779650 to your computer and use it in GitHub Desktop.
Save dnet/1779650 to your computer and use it in GitHub Desktop.
Simple Erlang URL unshortener
-module(unshort).
-export([unshort/1]).
unshort(URL) -> unshort(URL, 32).
unshort(URL, TTL) when TTL > 0 ->
{ok, {_, Headers, _}} = httpc:request(head, {URL, []}, [{autoredirect, false}], []),
case proplists:get_value("location", Headers) of
undefined -> URL;
Location -> unshort(Location, TTL - 1)
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment