expression

Transform a body frame

Map a body data frame without collecting the entire stream first. This example uppercases ASCII in a fixed byte buffer; a real transformation must preserve correct message headers and handle chunk boundaries, especially for UTF-8. In-memory fixture; no external connection. Expected stdout (not executed): ABC Common mistake: Using independent frame transformations for arbitrary multibyte text or keeping a stale Content-Length after changing body size.

Formal Syntax & Structure

rust syntaxrust
body.map_frame(|frame| frame.map_data(f))

Working Example

Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() {    use hyper::body::Bytes;    use http_body_util::{Full, BodyExt};    let body = Full::new(Bytes::from_static(b"abc")).map_frame(|f| {        f.map_data(|b| Bytes::from(b.to_ascii_uppercase()))    });    let bytes = body.collect().await.unwrap().to_bytes();    println!("{}", std::str::from_utf8(&bytes).unwrap());}
Rust Reference