Outbound body streaming using warp 0.4.2 server
⚓ Rust 📅 2025-10-31 👤 surdeus 👁️ 9What's the correct way to stream a file to client using warp 0.4.2 server?
Data is provided as a Box<dyn std::io::Read + std::marker::Send> reader. I'd like to control block size if possible.
I've encountered various type errors and trait implementation errors which led to an undesirable workaround:
use std::{io::Read, marker::Send};
use warp::{Reply, Rejection, reply::Response, reject::not_found};
async fn handle_request(/* ... */) -> Result<impl Reply, Rejection>
// --snip--
let mut reader: Box<dyn Read + Send> = crate::zip::stream_file(&relative_path)?;
let mut whole_file = Vec::new();
reader
.read_to_end(&mut whole_file)
.map_err(|_| not_found())?;
let mut response = Response::new(whole_file.into());
// --snip--
Ok(response)
}
The warp documentation wasn't helpful as I only found warp::filters entries which are for inbound streaming.
1 post - 1 participant
🏷️ Rust_feed