HTTP range responses for axum
.
MIT license.
use axum_extra::TypedHeader;
use axum_extra::headers::Range;
use tokio::fs::File;
use axum_range::Ranged;
use axum_range::KnownSize;
async fn file(range: Option<TypedHeader<Range>>) -> Ranged<KnownSize<File>> {
let file = File::open("archlinux-x86_64.iso").await.unwrap();
let body = KnownSize::file(file).await.unwrap();
let range = range.map(|TypedHeader(range)| range);
Ranged::new(range, body)
}