Crate warp_range

Crate warp_range 

Source
Expand description

§warp-range

A Rust library for creating a warp filter for serving file content with range like mp3 audio or mp4 video. This warp filter can be used in a HTTP server based on warp.

The content is served like streaming. If you view a movie served by this filter, you can seek through it even if the file is not completely downloaded.

Here is an easy example to add range to an existing warp server:

use hyper::{Body, Response};
use warp::{Filter, Reply, fs::{File, dir}};
use warp_range::{filter_range, get_range};
 
#[tokio::main]
async fn main() {
    let test_video = "/home/uwe/Videos/Drive.mkv";
     
    let port = 9860;
    println!("Running test server on http://localhost:{}", port);
 
    let route_get_range = 
        warp::path("getvideo")
        .and(warp::path::end())
        .and(filter_range())
        .and_then(move |range_header| get_range(range_header, test_video, "video/mp4"))
 
    let route_static = dir(".");
     
    let routes = route_get_range
        .or(route_static);
 
    warp::serve(routes)
        .run(([127, 0, 0, 1], port))
        .await;    
}

Functions§

filter_range
This function filters and extracts the “Range”-Header
get_range
This function retrives the range of bytes requested by the web client
get_range_with_cb
This function retrives the range of bytes requested by the web client. You can define a callback function for logging purpose or media access control