aboutsummaryrefslogtreecommitdiffstats
path: root/test/handlers
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-11-02 12:36:51 +0100
committerLoïc Hoguin <[email protected]>2018-11-02 13:49:54 +0100
commit399b6a16b4a571e293437dcc8f85808f83b32ff6 (patch)
tree5b1d5b0e06b1f3bf08f1a858770ff00fe3c2fe3f /test/handlers
parentd4dff2105500d960479d278981f42d42beb54175 (diff)
downloadcowboy-399b6a16b4a571e293437dcc8f85808f83b32ff6.tar.gz
cowboy-399b6a16b4a571e293437dcc8f85808f83b32ff6.tar.bz2
cowboy-399b6a16b4a571e293437dcc8f85808f83b32ff6.zip
Better handle content negotiation when accept contains charsets
Thanks to Philip Witty for help figuring this out.
Diffstat (limited to 'test/handlers')
-rw-r--r--test/handlers/charset_in_content_types_provided_h.erl22
-rw-r--r--test/handlers/charset_in_content_types_provided_implicit_h.erl24
-rw-r--r--test/handlers/charset_in_content_types_provided_implicit_no_callback_h.erl21
3 files changed, 67 insertions, 0 deletions
diff --git a/test/handlers/charset_in_content_types_provided_h.erl b/test/handlers/charset_in_content_types_provided_h.erl
new file mode 100644
index 0000000..4774407
--- /dev/null
+++ b/test/handlers/charset_in_content_types_provided_h.erl
@@ -0,0 +1,22 @@
+%% This module has a media type provided with an explicit charset.
+
+-module(charset_in_content_types_provided_h).
+
+-export([init/2]).
+-export([content_types_provided/2]).
+-export([charsets_provided/2]).
+-export([get_text_plain/2]).
+
+init(Req, Opts) ->
+ {cowboy_rest, Req, Opts}.
+
+content_types_provided(Req, State) ->
+ {[
+ {{<<"text">>, <<"plain">>, [{<<"charset">>, <<"utf-8">>}]}, get_text_plain}
+ ], Req, State}.
+
+charsets_provided(Req, State) ->
+ {[<<"utf-16">>, <<"iso-8861-1">>], Req, State}.
+
+get_text_plain(Req, State) ->
+ {<<"This is REST!">>, Req, State}.
diff --git a/test/handlers/charset_in_content_types_provided_implicit_h.erl b/test/handlers/charset_in_content_types_provided_implicit_h.erl
new file mode 100644
index 0000000..fcdd0c8
--- /dev/null
+++ b/test/handlers/charset_in_content_types_provided_implicit_h.erl
@@ -0,0 +1,24 @@
+%% This module has a media type provided with a wildcard
+%% and a list of charsets that is limited.
+
+-module(charset_in_content_types_provided_implicit_h).
+
+-export([init/2]).
+-export([content_types_provided/2]).
+-export([charsets_provided/2]).
+-export([get_text_plain/2]).
+
+init(Req, Opts) ->
+ {cowboy_rest, Req, Opts}.
+
+content_types_provided(Req, State) ->
+ {[
+ {{<<"text">>, <<"plain">>, '*'}, get_text_plain}
+ ], Req, State}.
+
+charsets_provided(Req, State) ->
+ {[<<"utf-8">>, <<"utf-16">>], Req, State}.
+
+get_text_plain(Req, State) ->
+ {<<"This is REST!">>, Req, State}.
+
diff --git a/test/handlers/charset_in_content_types_provided_implicit_no_callback_h.erl b/test/handlers/charset_in_content_types_provided_implicit_no_callback_h.erl
new file mode 100644
index 0000000..ae17af3
--- /dev/null
+++ b/test/handlers/charset_in_content_types_provided_implicit_no_callback_h.erl
@@ -0,0 +1,21 @@
+%% This module has a media type provided with a wildcard
+%% and lacks a charsets_provided callback.
+
+-module(charset_in_content_types_provided_implicit_no_callback_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, State) ->
+ {[
+ {{<<"text">>, <<"plain">>, '*'}, get_text_plain}
+ ], Req, State}.
+
+get_text_plain(Req, State) ->
+ {<<"This is REST!">>, Req, State}.
+
+