use std::sync::{Arc, Mutex};
#[derive(Clone, Debug, Default)]
pub struct RequestUrlCtx {
pub scheme: String,
pub host: String,
pub path: String,
pub query: Option<String>,
}
#[derive(Clone, Debug, Default)]
pub struct InitialTheme(pub Option<String>);
#[derive(Clone, Default)]
pub struct LeptosResponseOptions(Arc<Mutex<RespOptsInner>>);
#[derive(Default)]
struct RespOptsInner {
status: Option<u16>,
redirect: Option<String>,
headers: Vec<(String, String)>,
}
impl LeptosResponseOptions {
pub fn set_status(&self, code: u16) {
if let Ok(mut inner) = self.0.lock() {
inner.status = Some(code);
}
}
pub fn set_redirect(&self, url: impl Into<String>) {
if let Ok(mut inner) = self.0.lock() {
inner.redirect = Some(url.into());
}
}
pub fn insert_header(&self, name: impl Into<String>, value: impl Into<String>) {
if let Ok(mut inner) = self.0.lock() {
inner.headers.push((name.into(), value.into()));
}
}
pub fn status(&self) -> Option<u16> {
self.0.lock().ok().and_then(|i| i.status)
}
pub fn redirect(&self) -> Option<String> {
self.0.lock().ok().and_then(|i| i.redirect.clone())
}
pub fn take_headers(&self) -> Vec<(String, String)> {
self
.0
.lock()
.map(|mut i| std::mem::take(&mut i.headers))
.unwrap_or_default()
}
}