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