0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-16 05:00:24 +00:00

Add support for range requests (RFC7233) in cowboy_rest

This is currently undocumented but is planned to be documented
in the next version.
This commit is contained in:
Loïc Hoguin 2018-11-07 18:55:06 +01:00
parent bdd324ec01
commit 29043aa7b4
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
9 changed files with 745 additions and 9 deletions

View file

@ -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}.