0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-16 05:00:24 +00:00

allow POST rest handling to specify path after accepting content

This commit is contained in:
Tom Burdick 2012-10-23 14:37:46 -05:00
parent a59c5d6e91
commit 8a798014e9
3 changed files with 69 additions and 0 deletions

View file

@ -50,6 +50,7 @@
-export([onresponse_reply/1]).
-export([pipeline/1]).
-export([rest_bad_accept/1]).
-export([rest_created_path/1]).
-export([rest_expires/1]).
-export([rest_keepalive/1]).
-export([rest_keepalive_post/1]).
@ -112,6 +113,7 @@ groups() ->
nc_zero,
pipeline,
rest_bad_accept,
rest_created_path,
rest_expires,
rest_keepalive,
rest_keepalive_post,
@ -334,6 +336,7 @@ init_dispatch(Config) ->
{"/missing_put_callbacks", rest_missing_callbacks, []},
{"/nodelete", rest_nodelete_resource, []},
{"/patch", rest_patch_resource, []},
{"/created_path", rest_created_path_resource, []},
{"/resetags", rest_resource_etags, []},
{"/rest_expires", rest_expires, []},
{"/loop_timeout", http_handler_loop_timeout, []},
@ -763,6 +766,18 @@ rest_bad_accept(Config) ->
Client),
{ok, 400, _, _} = cowboy_client:response(Client2).
rest_created_path(Config) ->
Headers = [{<<"content-type">>, <<"text/plain">>}],
Body = <<"Whatever">>,
Client = ?config(client, Config),
URL = build_url("/created_path", Config),
{ok, Client2} = cowboy_client:request(<<"POST">>, URL, Headers,
Body, Client),
{ok, 303, ResHeaders, _} = cowboy_client:response(Client2),
{<<"location">>, _Location} =
lists:keyfind(<<"location">>, 1, ResHeaders),
ok.
rest_expires(Config) ->
Client = ?config(client, Config),
{ok, Client2} = cowboy_client:request(<<"GET">>,

View file

@ -0,0 +1,35 @@
-module(rest_created_path_resource).
-export([init/3]).
-export([allowed_methods/2]).
-export([content_types_provided/2]).
-export([get_text_plain/2]).
-export([post_is_create/2]).
-export([content_types_accepted/2]).
-export([post_text_plain/2]).
-export([created_path/2]).
init(_Transport, _Req, _Opts) ->
{upgrade, protocol, cowboy_rest}.
allowed_methods(Req, State) ->
{[<<"HEAD">>, <<"GET">>, <<"POST">>], Req, State}.
content_types_provided(Req, State) ->
{[{{<<"text">>, <<"plain">>, []}, get_text_plain}], Req, State}.
get_text_plain(Req, State) ->
{<<"This is REST!">>, Req, State}.
post_is_create(Req, State) ->
{true, Req, State}.
content_types_accepted(Req, State) ->
{[{{<<"text">>, <<"plain">>, []}, post_text_plain}], Req, State}.
post_text_plain(Req, State) ->
{true, Req, State}.
created_path(Req, State) ->
{<<"/created">>, Req, State}.