qubit_http/request/
http_request_body.rs1use std::fmt;
13
14use bytes::Bytes;
15use serde::{
16 Deserialize,
17 Serialize,
18};
19use strum::{
20 Display,
21 EnumString,
22};
23
24#[derive(Clone, PartialEq, Eq, Default, Serialize, Deserialize, Display, EnumString)]
26#[serde(rename_all = "snake_case")]
27#[strum(serialize_all = "snake_case")]
28pub enum HttpRequestBody {
29 #[default]
31 Empty,
32 #[strum(disabled)]
34 Bytes(Bytes),
35 #[strum(disabled)]
37 Text(String),
38 #[strum(disabled)]
40 Json(Bytes),
41 #[strum(disabled)]
43 Form(Bytes),
44 #[strum(disabled)]
46 Multipart(Bytes),
47 #[strum(disabled)]
49 Ndjson(Bytes),
50 #[strum(disabled)]
54 Stream(Vec<Bytes>),
55}
56
57impl fmt::Debug for HttpRequestBody {
58 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
59 match self {
60 Self::Empty => formatter.write_str("Empty"),
61 Self::Bytes(bytes) => formatter
62 .debug_struct("Bytes")
63 .field("len", &bytes.len())
64 .finish(),
65 Self::Text(text) => formatter
66 .debug_struct("Text")
67 .field("len", &text.len())
68 .finish(),
69 Self::Json(bytes) => formatter
70 .debug_struct("Json")
71 .field("len", &bytes.len())
72 .finish(),
73 Self::Form(bytes) => formatter
74 .debug_struct("Form")
75 .field("len", &bytes.len())
76 .finish(),
77 Self::Multipart(bytes) => formatter
78 .debug_struct("Multipart")
79 .field("len", &bytes.len())
80 .finish(),
81 Self::Ndjson(bytes) => formatter
82 .debug_struct("Ndjson")
83 .field("len", &bytes.len())
84 .finish(),
85 Self::Stream(chunks) => formatter
86 .debug_struct("Stream")
87 .field("chunks", &chunks.len())
88 .field("len", &chunks.iter().map(Bytes::len).sum::<usize>())
89 .finish(),
90 }
91 }
92}