| 1 |
%% This module defines the ranges_provided callback |
| 2 |
%% and return something different depending on query string. |
| 3 |
|
| 4 |
-module(ranges_provided_h). |
| 5 |
|
| 6 |
-export([init/2]). |
| 7 |
-export([content_types_provided/2]). |
| 8 |
-export([ranges_provided/2]). |
| 9 |
-export([get_text_plain/2]). |
| 10 |
|
| 11 |
init(Req, State) -> |
| 12 |
{cowboy_rest, Req, State}. |
| 13 |
|
| 14 |
content_types_provided(Req, State) -> |
| 15 |
{[{{<<"text">>, <<"plain">>, []}, get_text_plain}], Req, State}. |
| 16 |
|
| 17 |
ranges_provided(Req=#{qs := <<"list">>}, State) -> |
| 18 |
{[ |
| 19 |
{<<"bytes">>, get_text_plain_bytes}, |
| 20 |
{<<"pages">>, get_text_plain_pages}, |
| 21 |
{<<"chapters">>, get_text_plain_chapters} |
| 22 |
], Req, State}; |
| 23 |
ranges_provided(Req=#{qs := <<"none">>}, State) -> |
| 24 |
{[], Req, State}; |
| 25 |
%% Simulate the callback being missing in other cases. |
| 26 |
ranges_provided(_, _) -> |
| 27 |
no_call. |
| 28 |
|
| 29 |
get_text_plain(Req, State) -> |
| 30 |
{<<"This is REST!">>, Req, State}. |