Skip to content

Instantly share code, notes, and snippets.

@bipthelin
Created April 12, 2012 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bipthelin/2367925 to your computer and use it in GitHub Desktop.
Save bipthelin/2367925 to your computer and use it in GitHub Desktop.
Cowboy fail
-module(res_test).
-export([init/3, rest_init/2, allowed_methods/2]).
-export([content_types_provided/2]).
-export([get_resource/2]).
init(_Transport, _Req, _Opts) ->
{upgrade, protocol, cowboy_http_rest}.
rest_init(Req, _) ->
{ok, Req, []}.
allowed_methods(Req, State) ->
{['GET'], Req, State}.
content_types_provided(Req, State) ->
{[{{<<"application">>, <<"json">>, []}, get_resource},
{{<<"application">>, <<"xml">>, []}, get_resource}], Req, State}.
get_resource(Req, State) ->
{ok, Req2} = cowboy_http_req:reply(200, Req),
{ok, Req2, State}.
2012-04-12 16:57:07:005399 =ERROR REPORT=======
** Handler res_test terminating in rest_init/3
for the reason error:function_clause
** Options were []
** Request was [{socket,#Port<0.7134>},
{transport,cowboy_tcp_transport},
{connection,keepalive},
{pid,<0.115.0>},
{method,'GET'},
{version,{1,1}},
{peer,undefined},
{host,[<<"localhost">>]},
{host_info,undefined},
{raw_host,<<"localhost">>},
{port,8000},
{path,[<<"test">>]},
{path_info,undefined},
{raw_path,<<"/test">>},
{qs_vals,undefined},
{raw_qs,<<>>},
{bindings,[]},
{headers,
[{'Cookie',
<<"wp-settings-1=hidetb%3D0%26editor%3Dhtml; wp-settings-time-1=1314603036; _boss_session=c547cf10fd2ef73d23d069b0db52ee007a6c2702">>},
{'Accept-Charset',<<"ISO-8859-1,utf-8;q=0.7,*;q=0.3">>},
{'Accept-Language',<<"en-US,en;q=0.8">>},
{'Accept-Encoding',<<"gzip,deflate,sdch">>},
{'Accept',
<<"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8">>},
{'User-Agent',
<<"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1096.1 Safari/536.6">>},
{'Connection',<<"keep-alive">>},
{'Host',<<"localhost">>}]},
{p_headers,[{'Connection',[<<"keep-alive">>]}]},
{cookies,undefined},
{meta,[]},
{body_state,waiting},
{buffer,<<>>},
{resp_state,waiting},
{resp_headers,[]},
{resp_body,<<>>},
{urldecode,{#Fun<cowboy_http.urldecode.2>,crash}}]
** Stacktrace: [{cowboy_http_req,reply,
[200,[],ok,
{http_req,#Port<0.7134>,cowboy_tcp_transport,keepalive,
<0.115.0>,'GET',
{1,1},
undefined,
[<<"localhost">>],
undefined,<<"localhost">>,8000,
[<<"test">>],
undefined,<<"/test">>,undefined,<<>>,[],
[{'Cookie',
<<"wp-settings-1=hidetb%3D0%26editor%3Dhtml; wp-settings-time-1=1314603036; _boss_session=c547cf10fd2ef73d23d069b0db52ee007a6c2702">>},
{'Accept-Charset',
<<"ISO-8859-1,utf-8;q=0.7,*;q=0.3">>},
{'Accept-Language',<<"en-US,en;q=0.8">>},
{'Accept-Encoding',<<"gzip,deflate,sdch">>},
{'Accept',
<<"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8">>},
{'User-Agent',
<<"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1096.1 Safari/536.6">>},
{'Connection',<<"keep-alive">>},
{'Host',<<"localhost">>}],
[{'If-Modified-Since',undefined},
{'If-None-Match',undefined},
{'If-Unmodified-Since',undefined},
{'If-Match',undefined},
{'Accept',
[{{<<"text">>,<<"html">>,[]},1000,[]},
{{<<"application">>,<<"xhtml+xml">>,[]},
1000,[]},
{{<<"application">>,<<"xml">>,[]},900,[]},
{{<<"*">>,<<"*">>,[]},800,[]}]},
{'Connection',[<<"keep-alive">>]}],
undefined,
[{charset,undefined},
{media_type,{<<"application">>,<<"xml">>,[]}}],
waiting,<<>>,done,[],ok,
{#Fun<cowboy_http.urldecode.2>,crash}}],
[{file,"src/cowboy_http_req.erl"},{line,698}]},
{cowboy_http_rest,respond,3,
[{file,"src/cowboy_http_rest.erl"},{line,910}]},
{cowboy_http_rest,upgrade,4,
[{file,"src/cowboy_http_rest.erl"},{line,64}]},
{cowboy_http_protocol,upgrade_protocol,3,
[{file,"src/cowboy_http_protocol.erl"},{line,276}]}]
=ERROR REPORT==== 12-Apr-2012::16:57:07 ===
** Handler res_test terminating in rest_init/3
for the reason error:function_clause
** Options were []
** Request was [{socket,#Port<0.7134>},
{transport,cowboy_tcp_transport},
{connection,keepalive},
{pid,<0.115.0>},
{method,'GET'},
{version,{1,1}},
{peer,undefined},
{host,[<<"localhost">>]},
{host_info,undefined},
{raw_host,<<"localhost">>},
{port,8000},
{path,[<<"test">>]},
{path_info,undefined},
{raw_path,<<"/test">>},
{qs_vals,undefined},
{raw_qs,<<>>},
{bindings,[]},
{headers,
[{'Cookie',
<<"wp-settings-1=hidetb%3D0%26editor%3Dhtml; wp-settings-time-1=1314603036; _boss_session=c547cf10fd2ef73d23d069b0db52ee007a6c2702">>},
{'Accept-Charset',<<"ISO-8859-1,utf-8;q=0.7,*;q=0.3">>},
{'Accept-Language',<<"en-US,en;q=0.8">>},
{'Accept-Encoding',<<"gzip,deflate,sdch">>},
{'Accept',
<<"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8">>},
{'User-Agent',
<<"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1096.1 Safari/536.6">>},
{'Connection',<<"keep-alive">>},
{'Host',<<"localhost">>}]},
{p_headers,[{'Connection',[<<"keep-alive">>]}]},
{cookies,undefined},
{meta,[]},
{body_state,waiting},
{buffer,<<>>},
{resp_state,waiting},
{resp_headers,[]},
{resp_body,<<>>},
{urldecode,{#Fun<cowboy_http.urldecode.2>,crash}}]
** Stacktrace: [{cowboy_http_req,reply,
[200,[],ok,
{http_req,#Port<0.7134>,cowboy_tcp_transport,keepalive,
<0.115.0>,'GET',
{1,1},
undefined,
[<<"localhost">>],
undefined,<<"localhost">>,8000,
[<<"test">>],
undefined,<<"/test">>,undefined,<<>>,[],
[{'Cookie',
<<"wp-settings-1=hidetb%3D0%26editor%3Dhtml; wp-settings-time-1=1314603036; _boss_session=c547cf10fd2ef73d23d069b0db52ee007a6c2702">>},
{'Accept-Charset',
<<"ISO-8859-1,utf-8;q=0.7,*;q=0.3">>},
{'Accept-Language',<<"en-US,en;q=0.8">>},
{'Accept-Encoding',<<"gzip,deflate,sdch">>},
{'Accept',
<<"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8">>},
{'User-Agent',
<<"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1096.1 Safari/536.6">>},
{'Connection',<<"keep-alive">>},
{'Host',<<"localhost">>}],
[{'If-Modified-Since',undefined},
{'If-None-Match',undefined},
{'If-Unmodified-Since',undefined},
{'If-Match',undefined},
{'Accept',
[{{<<"text">>,<<"html">>,[]},1000,[]},
{{<<"application">>,<<"xhtml+xml">>,[]},
1000,[]},
{{<<"application">>,<<"xml">>,[]},900,[]},
{{<<"*">>,<<"*">>,[]},800,[]}]},
{'Connection',[<<"keep-alive">>]}],
undefined,
[{charset,undefined},
{media_type,{<<"application">>,<<"xml">>,[]}}],
waiting,<<>>,done,[],ok,
{#Fun<cowboy_http.urldecode.2>,crash}}],
[{file,"src/cowboy_http_req.erl"},{line,698}]},
{cowboy_http_rest,respond,3,
[{file,"src/cowboy_http_rest.erl"},{line,910}]},
{cowboy_http_rest,upgrade,4,
[{file,"src/cowboy_http_rest.erl"},{line,64}]},
{cowboy_http_protocol,upgrade_protocol,3,
[{file,"src/cowboy_http_protocol.erl"},{line,276}]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment