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

warp-range

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

5 releases (stable)

3.0.0 Dec 29, 2024
2.0.0 Feb 17, 2022
1.0.1 Jan 22, 2022
0.1.0 Jun 17, 2021

#472 in HTTP server

Download history 16/week @ 2024-09-24 7/week @ 2024-10-01 2/week @ 2024-12-03 20/week @ 2024-12-10 14/week @ 2024-12-17 101/week @ 2024-12-24 11/week @ 2024-12-31

147 downloads per month

MIT license

14KB
97 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

~8–19MB
~249K SLoC