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.debug_struct("Bytes").field("len", &bytes.len()).finish(),
62 Self::Text(text) => formatter.debug_struct("Text").field("len", &text.len()).finish(),
63 Self::Json(bytes) => formatter.debug_struct("Json").field("len", &bytes.len()).finish(),
64 Self::Form(bytes) => formatter.debug_struct("Form").field("len", &bytes.len()).finish(),
65 Self::Multipart(bytes) => formatter.debug_struct("Multipart").field("len", &bytes.len()).finish(),
66 Self::Ndjson(bytes) => formatter.debug_struct("Ndjson").field("len", &bytes.len()).finish(),
67 Self::Stream(chunks) => formatter
68 .debug_struct("Stream")
69 .field("chunks", &chunks.len())
70 .field("len", &chunks.iter().map(Bytes::len).sum::<usize>())
71 .finish(),
72 }
73 }
74}