| 1 |
%% This module returns something different in |
| 2 |
%% content_types_accepted depending on the query string. |
| 3 |
|
| 4 |
-module(content_types_accepted_h). |
| 5 |
|
| 6 |
-export([init/2]). |
| 7 |
-export([allowed_methods/2]). |
| 8 |
-export([content_types_accepted/2]). |
| 9 |
-export([put_multipart_mixed/2]). |
| 10 |
-export([put_text_plain/2]). |
| 11 |
|
| 12 |
init(Req, Opts) -> |
| 13 |
{cowboy_rest, Req, Opts}. |
| 14 |
|
| 15 |
allowed_methods(Req, State) -> |
| 16 |
{[<<"PUT">>], Req, State}. |
| 17 |
|
| 18 |
content_types_accepted(Req=#{qs := <<"multipart">>}, State) -> |
| 19 |
{[ |
| 20 |
{{<<"multipart">>, <<"mixed">>, [{<<"v">>, <<"1">>}]}, put_multipart_mixed} |
| 21 |
], Req, State}; |
| 22 |
content_types_accepted(Req=#{qs := <<"param">>}, State) -> |
| 23 |
{[{{<<"text">>, <<"plain">>, [{<<"charset">>, <<"utf-8">>}]}, put_text_plain}], Req, State}; |
| 24 |
content_types_accepted(Req=#{qs := <<"wildcard">>}, State) -> |
| 25 |
{[{'*', put_text_plain}], Req, State}; |
| 26 |
content_types_accepted(Req=#{qs := <<"wildcard-param">>}, State) -> |
| 27 |
{[{{<<"text">>, <<"plain">>, '*'}, put_text_plain}], Req, State}. |
| 28 |
|
| 29 |
put_multipart_mixed(Req, State) -> |
| 30 |
{true, Req, State}. |
| 31 |
|
| 32 |
put_text_plain(Req0, State) -> |
| 33 |
{ok, _, Req} = cowboy_req:read_body(Req0), |
| 34 |
{true, Req, State}. |