title: Erlang HTTP problems
body: <p>Can't make a request with Erlang/Cowboy at all. I can make one from the erlang shell but not when running a cowboy release. Tried using the 'hackney' library as well:</p>
  
  <pre><code>hackney:start(),
  
  {ok, _, _, Ref} = hackney:request(
    get, &lt;&lt;"http://www.youtube.com"&gt;&gt;, [], &lt;&lt;&gt;&gt;, [{pool, default}]
  ),
  {ok, Body} = hackney:body(Ref),
  io:format("body: ~p~n~n", [Body]),
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>Error in process &lt;0.361.0&gt; on node 'cta_erlang_backend@127.0.0.1' with exit value:
  {[{reason,undef},
    {mfa,{hello_handler,handle,2}},
    {stacktrace,[{hackney,start,[],[]},
                 {hello_handler,handle,2,
                                [{file,"src/hello_handler.erl"},{line,18}]},
                 {cowboy_handler,handler_handle,4,
                                 [{file,"src/cowboy_handler.erl"},{line,111}]},
                 {cowboy_protocol,execute,4,
                                  [{file,"src/cowboy_protocol.erl"},
                                   {line,442}]}]},
    {req,[{socket,#Port&lt;0.267&gt;},
          {transport,ranch_tcp},
          {connection,keepalive},
          {pid,&lt;0.361.0&gt;},
          {method,&lt;&lt;"POST"&gt;&gt;},
          {version,'HTTP/1.1'},
          {peer,{{10,0,0,1},40049}},
          {host,&lt;&lt;"10.0.0.103"&gt;&gt;},
          {host_info,undefined},
          {port,8080},
          {path,&lt;&lt;"/"&gt;&gt;},
          {path_info,undefined},
          {qs,&lt;&lt;&gt;&gt;},
          {qs_vals,undefined},
          {bindings,[]},
          {headers,[{&lt;&lt;"host"&gt;&gt;,&lt;&lt;"10.0.0.103:8080"&gt;&gt;},
                    {&lt;&lt;"connection"&gt;&gt;,&lt;&lt;"keep-alive"&gt;&gt;},
                    {&lt;&lt;"content-length"&gt;&gt;,&lt;&lt;"4"&gt;&gt;},
                    {&lt;&lt;"cache-control"&gt;&gt;,&lt;&lt;"no-cache"&gt;&gt;},
                    {&lt;&lt;"origin"&gt;&gt;,
                     &lt;&lt;"chrome-extension://fdmmgilgnpjigdojojpjoooidkmcomcm"&gt;&gt;},
                    {&lt;&lt;"user-agent"&gt;&gt;,
                     &lt;&lt;"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/39.0.2171.65 Chrome/39.0.2171.65 Safari/537.36"&gt;&gt;},
                    {&lt;&lt;"content-type"&gt;&gt;,&lt;&lt;"text/plain;charset=UTF-8"&gt;&gt;},
                    {&lt;&lt;"accept"&gt;&gt;,&lt;&lt;"*/*"&gt;&gt;},
                    {&lt;&lt;"accept-encoding"&gt;&gt;,&lt;&lt;"gzip, deflate"&gt;&gt;},
                    {&lt;&lt;"accept-language"&gt;&gt;,&lt;&lt;"en-GB,en-US;q=0.8,en;q=0.6"&gt;&gt;}]},
          {p_headers,[{&lt;&lt;"connection"&gt;&gt;,[&lt;&lt;"keep-alive"&gt;&gt;]}]},
          {cookies,undefined},
          {meta,[]},
          {body_state,waiting},
          {buffer,&lt;&lt;"asdf"&gt;&gt;},
          {multipart,undefined},
          {resp_compress,false},
          {resp_state,waiting},
          {resp_headers,[]},
          {resp_body,&lt;&lt;&gt;&gt;},
          {onresponse,undefined}]},
    {state,{state}}],
   [{cowboy_protocol,execute,4,[{file,"src/cowboy_protocol.erl"},{line,442}]}]}
  
  =ERROR REPORT==== 19-Oct-2016::18:56:51 ===
  Ranch listener my_http_listener had connection process started with cowboy_protocol:start_link/4 at &lt;0.361.0&gt; exit with reason:
  
  
  {[{reason,undef},{mfa,{hello_handler,handle,2}},{stacktrace,[{hackney,start,[],[]},{hello_handler,handle,2,[{file,"src/hello_handler.erl"},{line,18}]},{cowboy_handler,handler_handle,4,[{file,"src/cowboy_handler.erl"},{line,111}]},{cowboy_protocol,execute,4,[{file,"src/cowboy_protocol.erl"},{line,442}]}]},{req,[{socket,#Port&lt;0.267&gt;},{transport,ranch_tcp},{connection,keepalive},{pid,&lt;0.361.0&gt;},{method,&lt;&lt;"POST"&gt;&gt;},{version,'HTTP/1.1'},{peer,{{10,0,0,1},40049}},{host,&lt;&lt;"10.0.0.103"&gt;&gt;},{host_info,undefined},{port,8080},{path,&lt;&lt;"/"&gt;&gt;},{path_info,undefined},
  </code></pre>
  
  <p>{qs,&lt;&lt;>>},{qs_vals,undefined},{bindings,[]},{headers,[{&lt;&lt;"host">>,&lt;&lt;"10.0.0.103:8080">>},{&lt;&lt;"connection">>,&lt;&lt;"keep-alive">>},{&lt;&lt;"content-length">>,&lt;&lt;"4">>},{&lt;&lt;"cache-control">>,&lt;&lt;"no-cache">>},{&lt;&lt;"origin">>,&lt;&lt;"chrome-extension://fdmmgilgnpjigdojojpjoooidkmcomcm">>},{&lt;&lt;"user-agent">>,&lt;&lt;"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/39.0.2171.65 Chrome/39.0.2171.65 Safari/537.36">>},{&lt;&lt;"content-type">>,&lt;&lt;"text/plain;charset=UTF-8">>},{&lt;&lt;"accept">>,&lt;&lt;"<em>/</em>">>},{&lt;&lt;"accept-encoding">>,&lt;&lt;"gzip, deflate">>},{&lt;&lt;"accept-language">>,&lt;&lt;"en-GB,en-US;q=0.8,en;q=0.6">>}]},{p_headers,[{&lt;&lt;"connection">>,[&lt;&lt;"keep-alive">>]}]},{cookies,undefined},{meta,[]},{body_state,waiting},{buffer,&lt;&lt;"asdf">>},{multipart,undefined},{resp_compress,false},{resp_state,waiting},{resp_headers,[]},{resp_body,&lt;&lt;>>},{onresponse,undefined}]},{state,{state}}],[{cowboy_protocol,execute,4,[{file,"src/cowboy_protocol.erl"},{line,442}]}]}</p>
  
  <p>hello_handler.erl:</p>
  
  <pre><code>-module(hello_handler).
  -behaviour(cowboy_http_handler).
  
  -export([init/3]).
  -export([handle/2]).
  -export([terminate/3]).
  
  -record(state, {
  }).
  
  init(_, Req, _Opts) -&gt;
      hackney:start(),
      {ok, Req, #state{}}.
  
  handle(Req, State) -&gt;
      {Method, Req2} = cowboy_req:method(Req),
      case Method of
          &lt;&lt;"POST"&gt;&gt; -&gt;
              {ok, _, _, Ref} = hackney:request(get, &lt;&lt;"http://www.youtube.com"&gt;&gt;,
                  [], &lt;&lt;&gt;&gt;, [{pool, default}]),
              {ok, Body} = hackney:body(Ref),
              io:format("body: ~p~n~n", [Body]),
              ResponseBody = &lt;&lt;"Hello Erl POST!"&gt;&gt;;
          &lt;&lt;"GET"&gt;&gt; -&gt;
              ResponseBody = &lt;&lt;"Hello Erlang1!"&gt;&gt;
      end,
      {ok, Req2} = cowboy_req:reply(200,
          [{&lt;&lt;"content-type"&gt;&gt;, &lt;&lt;"text/plain"&gt;&gt;}],
          ResponseBody,
          Req),
      {ok, Req2, State}.
  
  terminate(_Reason, _Req, _State) -&gt;
      ok.
  </code></pre>