New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

partial implementation of rfc 7233 for cowboy_rest #1059

Closed
wants to merge 2 commits into
base: master
from

Conversation

Projects
None yet
2 participants
@s-kostyaev

s-kostyaev commented Dec 10, 2016

For full imlementation multipart/byteranges reply need to be implemented in cowboy.

@s-kostyaev

This comment has been minimized.

s-kostyaev commented Dec 10, 2016

You can see how to use it in this example:

%% callback for content type with ranges support
get_file(Req, State = #state{filepath = FilePath, is_range = true, range_offset = Offset, range_bytes = Bytes}) ->
    SendFile = fun(Socket, Transport) ->
        case Transport:sendfile(Socket, FilePath, Offset, Bytes) of
            {ok, _} -> ok;
            {error, closed} -> ok;
            {error, etimedout} -> ok
        end
               end,
    {{stream, Bytes, SendFile}, Req, State};
get_file(Req, State = #state{filepath = FilePath, file_info = #file_info{size = Size}}) ->
    SendFile = fun(Socket, Transport) ->
        case Transport:sendfile(Socket, FilePath) of
            {ok, _} -> ok;
            {error, closed} -> ok;
            {error, etimedout} -> ok
        end
               end,
    {{stream, Size, SendFile}, Req, State}.

%% callback for using http ranges
range_satisfiable(Req, State = #state{file_info = #file_info{size = Size}}) ->
    case cowboy_rest:range_satisfiable(Req, Size) of
        {true, Req1, Offset, Bytes} ->
            {true, Req1, State#state{is_range = true, range_offset = Offset,
                                     range_bytes = Bytes}};
        _ ->
            {false, Req, State#state{is_range = false}}
    end.
@essen

This comment has been minimized.

Member

essen commented Dec 10, 2016

Multipart is already supported so I'm not sure what you mean.

@s-kostyaev

This comment has been minimized.

s-kostyaev commented Dec 10, 2016

@essen please add link to doc. I need reply from cowboy with multipart, not receive multipart in cowboy.

@essen

This comment has been minimized.

Member

essen commented Dec 10, 2016

cow_multipart, no docs yet.

@s-kostyaev

This comment has been minimized.

s-kostyaev commented Dec 10, 2016

Thanks. We use branch 1.0. Maybe we complete rfc 7233 implementation later. Or you can merge this partial implementation and complete it yourself.

@s-kostyaev

This comment has been minimized.

s-kostyaev commented Dec 10, 2016

For now this implementation works fine with <audio> tag in firefox and google chrome.

@essen essen added this to the After 2.0 milestone Feb 4, 2017

@essen essen removed this from the After 2.0 milestone Oct 2, 2017

@essen

This comment has been minimized.

Member

essen commented Nov 5, 2018

I've started working on a full implementation of RFC7233. I may or may not take inspiration or some code from this PR. In the meantime I'll close it. Thanks!

@essen essen closed this Nov 5, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment