From 5a171d0f8050eda4e43de82efb7f2508be314ee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Thu, 11 Apr 2013 17:59:54 +0200 Subject: Remove process_post, post_is_create, create_path, created_path callbacks Instead it will always go through content_types_accepted and it is up to the resource code to do any creation and to return the created path if the method is POST and the client should be redirected to the created resource's location. This removes the meta value 'put_path' as it is not needed anymore. This fixes an issue with PATCH where content types were not normalized. --- test/http_SUITE.erl | 15 --------------- test/rest_created_path_resource.erl | 35 ----------------------------------- test/rest_forbidden_resource.erl | 15 +++------------ 3 files changed, 3 insertions(+), 62 deletions(-) delete mode 100644 test/rest_created_path_resource.erl (limited to 'test') diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl index 911efb8..e33e19a 100644 --- a/test/http_SUITE.erl +++ b/test/http_SUITE.erl @@ -54,7 +54,6 @@ -export([pipeline/1]). -export([pipeline_long_polling/1]). -export([rest_bad_accept/1]). --export([rest_created_path/1]). -export([rest_expires/1]). -export([rest_keepalive/1]). -export([rest_keepalive_post/1]). @@ -124,7 +123,6 @@ groups() -> pipeline, pipeline_long_polling, rest_bad_accept, - rest_created_path, rest_expires, rest_keepalive, rest_keepalive_post, @@ -364,7 +362,6 @@ 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, []}, @@ -882,18 +879,6 @@ 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">>, diff --git a/test/rest_created_path_resource.erl b/test/rest_created_path_resource.erl deleted file mode 100644 index 5ad8cfc..0000000 --- a/test/rest_created_path_resource.erl +++ /dev/null @@ -1,35 +0,0 @@ --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}. - - diff --git a/test/rest_forbidden_resource.erl b/test/rest_forbidden_resource.erl index 63aac7e..287ff62 100644 --- a/test/rest_forbidden_resource.erl +++ b/test/rest_forbidden_resource.erl @@ -1,7 +1,7 @@ -module(rest_forbidden_resource). -export([init/3, rest_init/2, allowed_methods/2, forbidden/2, content_types_provided/2, content_types_accepted/2, - post_is_create/2, create_path/2, to_text/2, from_text/2]). + to_text/2, from_text/2]). init(_Transport, _Req, _Opts) -> {upgrade, protocol, cowboy_rest}. @@ -23,18 +23,9 @@ content_types_provided(Req, State) -> content_types_accepted(Req, State) -> {[{{<<"text">>, <<"plain">>, []}, from_text}], Req, State}. -post_is_create(Req, State) -> - {true, Req, State}. - -create_path(Req, State) -> - {Path, Req2} = cowboy_req:path(Req), - {Path, Req2, State}. - to_text(Req, State) -> {<<"This is REST!">>, Req, State}. from_text(Req, State) -> - {true, Req, State}. - - - + {Path, Req2} = cowboy_req:path(Req), + {Path, Req2, State}. -- cgit v1.2.3