Created
February 9, 2012 12:28
-
-
Save dnet/1779650 to your computer and use it in GitHub Desktop.
Simple Erlang URL unshortener
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
-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