boostorg / beast

HTTP and WebSocket built on Boost.Asio in C++11
http://www.boost.org/libs/beast
Boost Software License 1.0
4.33k stars 634 forks source link

http_server_fast (http server file range support) #723

Open maytrue opened 7 years ago

maytrue commented 7 years ago

I modify http_server_fast demo, run as http server and return media data from file to vlc player.

I parse "Range: bytes=" to support range, and player can play well, but stop when seek to end.

http_server_fast stop at screen shot 2017-08-07 at 4 26 36 pm

vinniefalco commented 7 years ago

The file_body does not currently support serving a range, but I have done some of that work already. I can add a function which lets you specify the range you want to serve. I was thinking something like this:

template<class File>
class basic_file_body<File>::value_type
{
    ...
    /// Set the range of bytes to deliver
    void range(std::size_t first, std::size_t last);

To work around your issue, try this instead:

if(nread == 0)
    return boost::none;

Thanks

maytrue commented 7 years ago

It works, thanks

vinniefalco commented 7 years ago

I'll keep this open since I do plan to add built-in support for "range" on file_body.

ecorm commented 9 months ago

I'll keep this open since I do plan to add built-in support for "range" on file_body.

Was range support for file_body ever implemented? I'm scouring through the documentation and source code and can't find such support.

ecorm commented 9 months ago

I should add that I don't really need this range request support right now; I was just curious to know if it was supported.

ashtum commented 9 months ago

@ecorm No, there is no support for specifying a range in basic_file_body. However we can add this if you have a use case for it.

ecorm commented 9 months ago

@ecorm No, there is no support for specifying a range in basic_file_body. However we can add this if you have a use case for it.

The use case would obviously be video streaming: https://developer.mozilla.org/en-US/docs/Web/Media/Audio_and_video_delivery/Setting_up_adaptive_streaming_media_sources

I currently don't have a need for video streaming in my project, but I'm surprised range support hasn't been requested more by others.

A Beast-provided way of parsing the Range field would go nicely with file_body ranges if the latter were to be implemented.

vinniefalco commented 8 months ago

The use case would obviously be video streaming

Right, but are people using Beast to build video streamers? I doubt it, as there are already commercial solutions which Beast cannot hope to compete with. What I mean when I say use-case, is the specific motivating example which informs us on how to proceed (going in order of least design work to most design work):

  1. Define this as "responsibility of the user",
  2. Provide a working example using best practices upon which users can build, or
  3. Improve the Beast public API to support this

A Beast-provided way of parsing the Range field

Yes, I like this a lot! The design work is not difficult at all and it can't possibly affect existing programs. We could start with an example, get some feedback from users, and then promote it into a public API.

Thanks

ecorm commented 8 months ago

I'm not an expert in this area, but I imagine a video streaming server might want to do something more sophisticated than opening a file and read a part of it for every Range request that comes in. One might want to read ahead and cache parts of the file in memory in anticipation of the next Range requests that will soon come in.

I'll re-iterate that I don't have a requirement for video streaming in my project. I was just curious about the status of this issue.