#file-content #warp #range #filter #file-serving #mp4

warp-range

Warp filter for serving file content with range like mp3 audio or mp4 video

4 releases (stable)

2.0.0 Feb 17, 2022
1.0.1 Jan 22, 2022
0.1.0 Jun 17, 2021

#1041 in HTTP server

MIT license

12KB
98 lines

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.


lib.rs:

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;    
}

Dependencies

~9–22MB
~267K SLoC