Last active
September 25, 2015 18:48
-
-
Save ferd/a82b42a3cc509faebf83 to your computer and use it in GitHub Desktop.
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
meck:new(hackney, [passthrough]), | |
... | |
{ok, _, _, Ref1} = hackney:request("facebook.com"), hackney:body(Ref1), | |
{ok, _, _, Ref2} = hackney:request("google.com"), hackney:body(Ref2), | |
... | |
{_, Requests} = | |
lists:foldl(fun({_, {hackney, request, [Url|_]}, {ok, Status, Headers, Ref}}, {RMap, BMap}) -> | |
{RMap#{Ref=>Url}, BMap#{Url => {Status, Headers}}} | |
; ({_, {hackney, body, [Ref]}, Body}, {RMap, BMap}) -> | |
#{Ref := Url} = RMap, | |
#{Url := {Status,Headers}} = BMap, | |
{RMap, BMap#{Url => {Status, Headers, Body}}} | |
; (_, State) -> | |
State | |
end, | |
{#{}, #{}}, | |
meck:history(hackney). | |
... | |
Requests == | |
#{"facebook.com" => {302, | |
[{<<"Location">>,<<"https://facebook.com/">>}, | |
{<<"Content-Type">>,<<"text/html">>}, | |
{<<"X-FB-Debug">>, | |
<<"Cy5IWeTsPju/viKEkeGjXJcP+aYKjvjykQLr8TG5AzLEh1nVcBYzqfJNtYftOgvLh/k5agGDrfyf"...>>}, | |
{<<"Date">>,<<"Fri, 25 Sep 2015 18:33:25 GMT">>}, | |
{<<"Connection">>,<<"keep-alive">>}, | |
{<<"Content-Length">>,<<"0">>}], | |
{ok,<<>>}}, | |
"google.com" => {302, | |
[{<<"Cache-Control">>,<<"private">>}, | |
{<<"Content-Type">>,<<"text/html; charset=UTF-8">>}, | |
{<<"Location">>, | |
<<"http://www.google.ca/?gfe_rd=cr&ei=a5MFVvDsH-nK8ge7-pHQCA">>}, | |
{<<"Content-Length">>,<<"258">>}, | |
{<<"Date">>,<<"Fri, 25 Sep 2015 18:33:15 GMT">>}, | |
{<<"Server">>,<<"GFE/2.0">>}], | |
{ok,<<"<HTML><HEAD><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">\ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment