diff options
author | Loïc Hoguin <[email protected]> | 2018-11-07 18:55:06 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2018-11-07 18:55:06 +0100 |
commit | 29043aa7b4d11e377bc76d453f592ea5a6df1f43 (patch) | |
tree | 921c9439bd9678f7e06c87f460f8ff892b350292 /test/handlers/ranges_provided_h.erl | |
parent | bdd324ec01b134be22e3fde73dfa75d6e56dfc0d (diff) | |
download | cowboy-29043aa7b4d11e377bc76d453f592ea5a6df1f43.tar.gz cowboy-29043aa7b4d11e377bc76d453f592ea5a6df1f43.tar.bz2 cowboy-29043aa7b4d11e377bc76d453f592ea5a6df1f43.zip |
Add support for range requests (RFC7233) in cowboy_rest
This is currently undocumented but is planned to be documented
in the next version.
Diffstat (limited to 'test/handlers/ranges_provided_h.erl')
-rw-r--r-- | test/handlers/ranges_provided_h.erl | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/handlers/ranges_provided_h.erl b/test/handlers/ranges_provided_h.erl new file mode 100644 index 0000000..8e2b050 --- /dev/null +++ b/test/handlers/ranges_provided_h.erl @@ -0,0 +1,30 @@ +%% This module defines the ranges_provided callback +%% and return something different depending on query string. + +-module(ranges_provided_h). + +-export([init/2]). +-export([content_types_provided/2]). +-export([ranges_provided/2]). +-export([get_text_plain/2]). + +init(Req, State) -> + {cowboy_rest, Req, State}. + +content_types_provided(Req, State) -> + {[{{<<"text">>, <<"plain">>, []}, get_text_plain}], Req, State}. + +ranges_provided(Req=#{qs := <<"list">>}, State) -> + {[ + {<<"bytes">>, get_text_plain_bytes}, + {<<"pages">>, get_text_plain_pages}, + {<<"chapters">>, get_text_plain_chapters} + ], Req, State}; +ranges_provided(Req=#{qs := <<"none">>}, State) -> + {[], Req, State}; +%% Simulate the callback being missing in other cases. +ranges_provided(_, _) -> + no_call. + +get_text_plain(Req, State) -> + {<<"This is REST!">>, Req, State}. |