aboutsummaryrefslogtreecommitdiffstats
path: root/test/handlers
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-11-02 13:54:19 +0100
committerLoïc Hoguin <[email protected]>2018-11-02 13:54:19 +0100
commite0b036fe68579b3ffb69b450acf2d17bb7162cf3 (patch)
tree4be263290f0ae3bef6b9bd940f6624cf035607d3 /test/handlers
parent399b6a16b4a571e293437dcc8f85808f83b32ff6 (diff)
downloadcowboy-e0b036fe68579b3ffb69b450acf2d17bb7162cf3.tar.gz
cowboy-e0b036fe68579b3ffb69b450acf2d17bb7162cf3.tar.bz2
cowboy-e0b036fe68579b3ffb69b450acf2d17bb7162cf3.zip
Add tests for charsets_provided
Fix cases where the q-value is 0 and where a wildcard was sent in the accept-charset header. Also don't send a charset in the content-type of the response if the media type is not text. Thanks to Philip Witty for help figuring this out.
Diffstat (limited to 'test/handlers')
-rw-r--r--test/handlers/charsets_provided_empty_h.erl30
-rw-r--r--test/handlers/charsets_provided_h.erl28
2 files changed, 58 insertions, 0 deletions
diff --git a/test/handlers/charsets_provided_empty_h.erl b/test/handlers/charsets_provided_empty_h.erl
new file mode 100644
index 0000000..0548a5e
--- /dev/null
+++ b/test/handlers/charsets_provided_empty_h.erl
@@ -0,0 +1,30 @@
+%% This module has a text and non-text media type,
+%% but provides no charset. All requests will result
+%% in a 406 not acceptable.
+
+-module(charsets_provided_empty_h).
+
+-export([init/2]).
+-export([content_types_provided/2]).
+-export([charsets_provided/2]).
+-export([get_text_plain/2]).
+-export([get_application_json/2]).
+
+init(Req, Opts) ->
+ {cowboy_rest, Req, Opts}.
+
+content_types_provided(Req, State) ->
+ {[
+ {{<<"text">>, <<"plain">>, []}, get_text_plain},
+ {{<<"application">>, <<"json">>, []}, get_application_json}
+ ], Req, State}.
+
+charsets_provided(Req, State) ->
+ {[], Req, State}.
+
+get_text_plain(Req, State) ->
+ {<<"This is REST!">>, Req, State}.
+
+get_application_json(Req, State) ->
+ {<<"{\"hello\": \"rest\"}">>, Req, State}.
+
diff --git a/test/handlers/charsets_provided_h.erl b/test/handlers/charsets_provided_h.erl
new file mode 100644
index 0000000..4a08e78
--- /dev/null
+++ b/test/handlers/charsets_provided_h.erl
@@ -0,0 +1,28 @@
+%% This module has a text and non-text media type,
+%% and provides two charsets.
+
+-module(charsets_provided_h).
+
+-export([init/2]).
+-export([content_types_provided/2]).
+-export([charsets_provided/2]).
+-export([get_text_plain/2]).
+-export([get_application_json/2]).
+
+init(Req, Opts) ->
+ {cowboy_rest, Req, Opts}.
+
+content_types_provided(Req, State) ->
+ {[
+ {{<<"text">>, <<"plain">>, []}, get_text_plain},
+ {{<<"application">>, <<"json">>, []}, get_application_json}
+ ], Req, State}.
+
+charsets_provided(Req, State) ->
+ {[<<"utf-8">>, <<"utf-16">>], Req, State}.
+
+get_text_plain(Req, State) ->
+ {<<"This is REST!">>, Req, State}.
+
+get_application_json(Req, State) ->
+ {<<"{\"hello\": \"rest\"}">>, Req, State}.