mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 20:30:23 +00:00
Add automatic ranged request handling for bytes units
Returning the atom auto instead of a callback informs Cowboy that it needs to handle range requests automatically. This changes the behavior so that the ProvideCallback function is called and then Cowboy splits the data on its own and sends the response without any other user involvement other than defining the ranges_provided/2 callback. This is a quick and dirty way to add range request support to resources, and will be good enough for many cases including for cowboy_static as it also works when the normal response body is a sendfile tuple.
This commit is contained in:
parent
d7b7580b39
commit
dd0fbab6b7
4 changed files with 357 additions and 24 deletions
|
@ -1,4 +1,4 @@
|
|||
%% This module defines the range_satisfiable callback
|
||||
%% This module defines many callbacks relevant to range requests
|
||||
%% and return something different depending on query string.
|
||||
|
||||
-module(provide_range_callback_h).
|
||||
|
@ -41,7 +41,7 @@ get_text_plain(Req, State) ->
|
|||
|
||||
%% Simulate the callback being missing, otherwise expect true/false.
|
||||
get_text_plain_bytes(#{qs := <<"missing">>}, _) ->
|
||||
ct_helper_error_h:ignore(cowboy_rest, set_ranged_body, 3),
|
||||
ct_helper_error_h:ignore(cowboy_rest, set_ranged_body_callback, 3),
|
||||
no_call;
|
||||
get_text_plain_bytes(Req=#{range := {_, [{From=0, infinity}]}}, State) ->
|
||||
%% We send everything in one part.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue