use std::fmt::Display;
use std::sync::Arc;
use crate::IntoArcStr;
use http::Method;
#[derive(Debug, Clone)]
pub struct RequestData {
pub method: Method,
pub uri: Arc<str>,
pub body: Option<serde_json::Value>,
}
impl RequestData {
pub fn new<S: IntoArcStr>(method: Method, uri: S) -> Self {
RequestData {
method,
uri: uri.into(),
body: None,
}
}
pub fn add_body(mut self, body: serde_json::Value) -> Self {
self.body = Some(body);
self
}
}
impl Display for RequestData {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if let Some(body) = &self.body {
write!(
f,
"{} {} {}",
self.method,
self.uri,
serde_json::to_string(body).unwrap_or_default()
)
} else {
write!(f, "{} {}", self.method, self.uri)
}
}
}