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

Loïc Hoguin essen at ninenines.eu
Tue Jul 8 11:57:12 CEST 2014


It's not enabled for PATCH or PUT because it makes little sense for 
them. PATCH and PUT are typically used directly on the URI of the 
resource, even when creating it. While you can return a "better URI" for 
the created resource for them, this should be seen as a special case 
rather than the norm. You can still do it by setting the location header 
manually and Cowboy will react accordingly.

On 07/08/2014 09:12 AM, Samuel wrote:
> 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}]}]}
>

-- 
Loïc Hoguin
http://ninenines.eu


More information about the Extend mailing list