Skip to main content

byte_range

Function byte_range 

Source
pub fn byte_range(
    content_type: &str,
    full: &Bytes,
    range: Option<(u64, u64)>,
) -> Response
Expand description

Serve a (possibly partial) byte range from a fully-buffered resource.

Pass the parsed range as an inclusive (start, end) over full; returns 206 Partial Content with Content-Range/Accept-Ranges when a range is given (and satisfiable), otherwise 200 OK with the whole body. Designed for media delivery (HLS/DASH segments, progressive download).

use arcly_http::http::{byte_range, Bytes};
let full = Bytes::from_static(b"0123456789");
let partial = byte_range("video/mp4", &full, Some((2, 5)));
assert_eq!(partial.status().as_u16(), 206);
let whole = byte_range("video/mp4", &full, None);
assert_eq!(whole.status().as_u16(), 200);