expires_h.erl 766 B

12345678910111213141516171819202122232425262728
  1. %% This module sends a different expires value
  2. %% depending on the query string.
  3. -module(expires_h).
  4. -export([init/2]).
  5. -export([content_types_provided/2]).
  6. -export([get_text_plain/2]).
  7. -export([expires/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. expires(Req=#{qs := <<"tuple">>}, State) ->
  15. {{{2012, 9, 21}, {22, 36, 14}}, Req, State};
  16. expires(Req=#{qs := <<"binary">>}, State) ->
  17. {<<"0">>, Req, State};
  18. expires(Req=#{qs := <<"undefined">>}, State) ->
  19. {undefined, Req, State};
  20. %% Simulate the callback being missing in other cases.
  21. expires(#{qs := <<"missing">>}, _) ->
  22. no_call.