Debian Codegraph @

test/handlers/ranges_provided_auto_h.erl

raw
1 %% This module defines the ranges_provided callback
2 %% which returns the auto option for bytes ranges
3 %% and the normal ProvideCallback that returns
4 %% something different depending on query string.
5
6 -module(ranges_provided_auto_h).
7
8 -export([init/2]).
9 -export([content_types_provided/2]).
10 -export([ranges_provided/2]).
11 -export([get_text_plain/2]).
12
13 init(Req, State) ->
14 {cowboy_rest, Req, State}.
15
16 content_types_provided(Req, State) ->
17 {[{{<<"text">>, <<"plain">>, []}, get_text_plain}], Req, State}.
18
19 ranges_provided(Req, State) ->
20 {[{<<"bytes">>, auto}], Req, State}.
21
22 get_text_plain(Req=#{qs := <<"data">>}, State) ->
23 {<<"This is ranged REST!">>, Req, State};
24 get_text_plain(Req=#{qs := <<"sendfile">>}, State) ->
25 Path = code:lib_dir(cowboy) ++ "/ebin/cowboy.app",
26 Size = filelib:file_size(Path),
27 {{sendfile, 0, Size, Path}, Req, State}.