last_modified_h.erl 653 B

123456789101112131415161718192021222324
  1. %% This module sends a different last-modified value
  2. %% depending on the query string.
  3. -module(last_modified_h).
  4. -export([init/2]).
  5. -export([content_types_provided/2]).
  6. -export([get_text_plain/2]).
  7. -export([last_modified/2]).
  8. init(Req, Opts) ->
  9. {cowboy_rest, Req, Opts}.
  10. content_types_provided(Req, State) ->
  11. {[{{<<"text">>, <<"plain">>, []}, get_text_plain}], Req, State}.
  12. get_text_plain(Req, State) ->
  13. {<<"This is REST!">>, Req, State}.
  14. last_modified(Req=#{qs := <<"tuple">>}, State) ->
  15. {{{2012, 9, 21}, {22, 36, 14}}, Req, State};
  16. %% Simulate the callback being missing in other cases.
  17. last_modified(#{qs := <<"missing">>}, _) ->
  18. no_call.