accept_callback_h.erl 622 B

1234567891011121314151617181920212223
  1. %% This module returns something different in
  2. %% AcceptCallback depending on the query string.
  3. -module(accept_callback_h).
  4. -export([init/2]).
  5. -export([allowed_methods/2]).
  6. -export([content_types_accepted/2]).
  7. -export([put_text_plain/2]).
  8. init(Req, Opts) ->
  9. {cowboy_rest, Req, Opts}.
  10. allowed_methods(Req, State) ->
  11. {[<<"PUT">>, <<"POST">>, <<"PATCH">>], Req, State}.
  12. content_types_accepted(Req, State) ->
  13. {[{{<<"text">>, <<"plain">>, []}, put_text_plain}], Req, State}.
  14. put_text_plain(Req=#{qs := <<"false">>}, State) ->
  15. {false, Req, State};
  16. put_text_plain(Req=#{qs := <<"true">>}, State) ->
  17. {true, Req, State}.