[99s-extend] [cowboy REST] returning {true, URL} to PUT

Samuel samuelrivas at gmail.com
Tue Jul 8 09:12:43 CEST 2014


Hi,

According to the documentation I should be able to return a new
location when handling a PUT request when using cowboy_rest protocol:

    The AcceptResource value is the name of the callback that will be
called if the
    content-type matches. It is defined as follow.

    Value type: true | {true, URL} | false

That works for "true" and "false" but not for "{true, URL}", in that
case the Ranch listener crashes badly[1].

Looking into cowboy_rest.erl I see that the {true, URL} form is
restricted to POST requests:
https://github.com/extend/cowboy/blob/master/src/cowboy_rest.erl#L784

Is that intentional or should I submit a patch to add at least PUT and
PATCH to that condition (or remove all of them if that is not guarding
against something horrible)?

Regards

[1] Ranch crash log:
Ranch listener http_acceptor had connection process started with
cowboy_protocol:start_link/4 at <0.2660.0> exit with reason:
{{case_clause,{{true,"/url"},{http_req,#Port<0.15864>,ranch_tcp,keepalive,<0.2660.0>,<<"PUT">>,'HTTP/1.1',{{127,0,0,1},56983},<<"localhost">>,undefined,8080,<<"/order">>,undefined,<<>>,undefined,[],[{<<"user-agent">>,<<"curl/7.22.0
(x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4
libidn/1.23 librtmp/2.3">>},{<<"host">>,<<"localhost:8080">>},{<<"accept">>,<<"*/*">>},{<<"content-type">>,<<"application/json">>}],[{<<"content-type">>,{<<"application">>,<<"json">>,[]}},{<<"if-modified-since">>,undefined},{<<"if-none-match">>,undefined},{<<"if-unmodified-since">>,undefined},{<<"if-match">>,undefined},{<<"accept">>,[{{<<"*">>,<<"*">>,[]},1000,[]}]}],undefined,[{charset,undefined},{media_type,{<<"text">>,<<"html">>,[]}}],waiting,undefined,<<>>,false,waiting,[{<<"content-type">>,[<<"text">>,<<"/">>,<<"html">>,<<>>]}],<<>>,undefined},{state}}},[{cowboy_rest,process_content_type,3,[{file,"src/cowboy_rest.erl"},{line,780}]},{cowboy_protocol,execute,4,[{file,"src/cowboy_protocol.erl"},{line,529}]}]}
-- 
Samuel


More information about the Extend mailing list