gproxy_protocol/connection/
body.rs1use std::{fmt, pin::Pin};
2
3use futures_core::Stream;
4
5use super::{Bytes, HeaderMap, TransportError};
6
7#[cfg(not(target_arch = "wasm32"))]
10pub type ByteStream = Pin<Box<dyn Stream<Item = Result<Bytes, TransportError>> + Send + 'static>>;
11
12#[cfg(target_arch = "wasm32")]
13pub type ByteStream = Pin<Box<dyn Stream<Item = Result<Bytes, TransportError>> + 'static>>;
14
15pub enum HttpBody {
18 Bytes(Bytes),
19 Stream(ByteStream),
20}
21
22impl fmt::Debug for HttpBody {
23 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24 match self {
25 Self::Bytes(bytes) => f.debug_struct("Bytes").field("len", &bytes.len()).finish(),
26 Self::Stream(_) => f.write_str("Stream(..)"),
27 }
28 }
29}
30
31#[derive(Debug, Clone, Copy, PartialEq, Eq)]
38pub enum StreamFraming {
39 Sse,
40 JsonArray,
42 NdJson,
44}
45
46#[cfg(not(target_arch = "wasm32"))]
49pub type PartStream =
50 Pin<Box<dyn Stream<Item = Result<MultipartPart, TransportError>> + Send + 'static>>;
51
52#[cfg(target_arch = "wasm32")]
53pub type PartStream = Pin<Box<dyn Stream<Item = Result<MultipartPart, TransportError>> + 'static>>;
54
55pub struct Multipart {
62 pub parts: PartStream,
63}
64
65impl fmt::Debug for Multipart {
66 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
67 f.write_str("Multipart { parts: .. }")
68 }
69}
70
71#[derive(Debug)]
72pub struct MultipartPart {
73 pub headers: HeaderMap,
74 pub body: HttpBody,
75}
76
77#[cfg(feature = "schema")]
80impl schemars::JsonSchema for MultipartPart {
81 fn schema_name() -> std::borrow::Cow<'static, str> {
82 "BinaryPart".into()
83 }
84
85 fn json_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema {
86 schemars::json_schema!({ "type": "string", "format": "binary" })
87 }
88}