Debian Codegraph @

test/handlers/content_types_provided_h.erl

raw
1 %% This module has different content_types_provided values
2 %% and/or sends a different response body depending on the
3 %% query string.
4
5 -module(content_types_provided_h).
6
7 -export([init/2]).
8 -export([content_types_provided/2]).
9 -export([get_text_plain/2]).
10
11 init(Req, Opts) ->
12 {cowboy_rest, Req, Opts}.
13
14 content_types_provided(Req=#{qs := <<"invalid-type">>}, State) ->
15 ct_helper:ignore(cowboy_rest, normalize_content_types, 2),
16 {[{{'*', '*', '*'}, get_text_plain}], Req, State};
17 content_types_provided(Req=#{qs := <<"wildcard-param">>}, State) ->
18 {[{{<<"text">>, <<"plain">>, '*'}, get_text_plain}], Req, State}.
19
20 get_text_plain(Req=#{qs := <<"invalid-type">>}, State) ->
21 {<<"invalid-type">>, Req, State};
22 get_text_plain(Req=#{qs := <<"wildcard-param">>}, State) ->
23 {_, _, Param} = maps:get(media_type, Req),
24 Body = if
25 Param =:= [] -> <<"[]">>;
26 Param =/= [] ->
27 iolist_to_binary([[Key, $=, Value] || {Key, Value} <- Param])
28 end,
29 {Body, Req, State}.