1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//! Shared body type used throughout the server.
//!
//! [`BoxBody`] is a type-erased HTTP body that supports both buffered and
//! streaming responses. Handlers return `Response<BoxBody>`.
use Bytes;
use UnsyncBoxBody;
use ;
/// The response body type used by typeway handlers.
///
/// This is a type-erased body that can wrap buffered data (`Full<Bytes>`),
/// streaming data, or an empty body. It implements `http_body::Body`.
///
/// Uses `UnsyncBoxBody` internally, which only requires `Send` (not `Sync`),
/// enabling streaming bodies from channels and other async sources.
pub type BoxBody = ;
/// Error type for the boxed body. Infallible for buffered bodies,
/// but allows streaming bodies to report errors.
pub type BoxBodyError = ;
/// Create a `BoxBody` from bytes.
/// Create a `BoxBody` from a string.
/// Create an empty `BoxBody`.
/// Create a streaming `BoxBody` from a `Stream` of `Result<Frame<Bytes>, E>`.
///
/// Use this for Server-Sent Events, chunked responses, or any streaming body.
/// The stream only needs to be `Send` — `Sync` is not required.
///
/// # Example
///
/// ```ignore
/// use futures::stream;
/// use http_body::Frame;
///
/// let chunks = stream::iter(vec![
/// Ok(Frame::data(Bytes::from("chunk 1\n"))),
/// Ok(Frame::data(Bytes::from("chunk 2\n"))),
/// ]);
/// let body = body_from_stream(chunks);
/// ```
/// Create an SSE (Server-Sent Events) body from a stream of event strings.
///
/// Each string in the stream is formatted as an SSE event (`data: ...\n\n`).
/// The stream only needs to be `Send`.
///
/// # Example
///
/// ```ignore
/// use futures::stream;
///
/// let events = stream::iter(vec!["hello", "world"]);
/// let body = sse_body(events.map(|s| s.to_string()));
/// ```