Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move many old HTTP test cases to the rest_handler test suite
A bug was fixed in cowboy_rest where when content_types_provided returned a media type with a wildcard as first in the list, and a request comes in without an accept header, then the media_type value in the Req object would contain '*' instead of [] for the parameters.
- Loading branch information
Showing
8 changed files
with
297 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-module(accept_callback_missing_h). | ||
|
||
-export([init/2]). | ||
-export([allowed_methods/2]). | ||
-export([content_types_accepted/2]). | ||
|
||
init(Req, State) -> | ||
{cowboy_rest, Req, State}. | ||
|
||
allowed_methods(Req, State) -> | ||
{[<<"PUT">>], Req, State}. | ||
|
||
content_types_accepted(Req, State) -> | ||
ct_helper_error_h:ignore(cowboy_rest, process_content_type, 3), | ||
{[{<<"text/plain">>, accept}], Req, State}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
%% This module has different content_types_provided values | ||
%% and/or sends a different response body depending on the | ||
%% query string. | ||
|
||
-module(content_types_provided_h). | ||
|
||
-export([init/2]). | ||
-export([content_types_provided/2]). | ||
-export([get_text_plain/2]). | ||
|
||
init(Req, Opts) -> | ||
{cowboy_rest, Req, Opts}. | ||
|
||
content_types_provided(Req=#{qs := <<"wildcard-param">>}, State) -> | ||
{[{{<<"text">>, <<"plain">>, '*'}, get_text_plain}], Req, State}. | ||
|
||
get_text_plain(Req=#{qs := <<"wildcard-param">>}, State) -> | ||
{_, _, Param} = maps:get(media_type, Req), | ||
Body = if | ||
Param =:= [] -> <<"[]">>; | ||
Param =/= [] -> | ||
iolist_to_binary([[Key, $=, Value] || {Key, Value} <- Param]) | ||
end, | ||
{Body, Req, State}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
%% This module sends a different expires value | ||
%% depending on the query string. | ||
|
||
-module(expires_h). | ||
|
||
-export([init/2]). | ||
-export([content_types_provided/2]). | ||
-export([get_text_plain/2]). | ||
-export([expires/2]). | ||
|
||
init(Req, Opts) -> | ||
{cowboy_rest, Req, Opts}. | ||
|
||
content_types_provided(Req, State) -> | ||
{[{{<<"text">>, <<"plain">>, []}, get_text_plain}], Req, State}. | ||
|
||
get_text_plain(Req, State) -> | ||
{<<"This is REST!">>, Req, State}. | ||
|
||
expires(Req=#{qs := <<"tuple">>}, State) -> | ||
{{{2012, 9, 21}, {22, 36, 14}}, Req, State}; | ||
expires(Req=#{qs := <<"binary">>}, State) -> | ||
{<<"0">>, Req, State}; | ||
expires(Req=#{qs := <<"undefined">>}, State) -> | ||
{undefined, Req, State}; | ||
%% Simulate the callback being missing in other cases. | ||
expires(#{qs := <<"missing">>}, _) -> | ||
no_call. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
%% This module sends a different last-modified value | ||
%% depending on the query string. | ||
|
||
-module(last_modified_h). | ||
|
||
-export([init/2]). | ||
-export([content_types_provided/2]). | ||
-export([get_text_plain/2]). | ||
-export([last_modified/2]). | ||
|
||
init(Req, Opts) -> | ||
{cowboy_rest, Req, Opts}. | ||
|
||
content_types_provided(Req, State) -> | ||
{[{{<<"text">>, <<"plain">>, []}, get_text_plain}], Req, State}. | ||
|
||
get_text_plain(Req, State) -> | ||
{<<"This is REST!">>, Req, State}. | ||
|
||
last_modified(Req=#{qs := <<"tuple">>}, State) -> | ||
{{{2012, 9, 21}, {22, 36, 14}}, Req, State}; | ||
%% Simulate the callback being missing in other cases. | ||
last_modified(#{qs := <<"missing">>}, _) -> | ||
no_call. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.