pub async fn get_range_with_cb(
range_header: Option<String>,
file: &str,
content_type: &str,
progress: fn(size: u64),
) -> Result<impl Reply, Rejection>Expand description
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
Examples found in repository?
examples/hello.rs (lines 34-36)
24async fn main() {
25 let test_video = "/home/uwe/Videos/Ali.mkv";
26
27 let port = 9860;
28 println!("Running test server on http://localhost:{}", port);
29
30 let route_get_video =
31 warp::path("getvideo")
32 .and(warp::path::end())
33 .and(filter_range())
34 .and_then(move |range_header| get_range_with_cb(range_header, test_video, "video/mp4", |bytes| {
35 callback(bytes);
36 }));
37
38 let route_static = dir(".")
39 .map(add_headers);
40
41 let routes =
42 route_get_video
43 .or(route_static);
44
45 warp::serve(routes)
46 .run(([127, 0, 0, 1], port))
47 .await;
48}