reorganize redirection Box

This commit is contained in:
yggverse 2025-03-27 19:54:21 +02:00
parent f2fb3c36ba
commit e3477d2056
3 changed files with 25 additions and 13 deletions

View file

@ -23,7 +23,7 @@ pub struct Info {
mime: Option<String>, mime: Option<String>,
/// Hold redirections chain with handled details /// Hold redirections chain with handled details
/// * the `referrer` member name is reserved for other protocols /// * the `referrer` member name is reserved for other protocols
redirect: Option<Box<Redirect>>, redirect: Option<Redirect>,
/// Key to relate data collected with the specific request /// Key to relate data collected with the specific request
request: Option<String>, request: Option<String>,
/// Hold size info /// Hold size info
@ -49,20 +49,16 @@ impl Info {
} }
} }
/// Take `Self`, convert it into the new `Redirect` member, pub fn into_permanent_redirect(self) -> Self {
/// * return new `Self` that contain referring node
fn into_redirect(self, method: redirect::Method) -> Self {
let mut this = Self::new(); let mut this = Self::new();
this.redirect = Some(Box::new(Redirect { info: self, method })); this.redirect = Some(Redirect::permanent(self));
this this
} }
pub fn into_permanent_redirect(self) -> Self {
self.into_redirect(redirect::Method::Permanent)
}
pub fn into_temporary_redirect(self) -> Self { pub fn into_temporary_redirect(self) -> Self {
self.into_redirect(redirect::Method::Temporary) let mut this = Self::new();
this.redirect = Some(Redirect::temporary(self));
this
} }
// Actions // Actions

View file

@ -202,7 +202,7 @@ impl Dialog for PreferencesDialog {
fn chain<'a>(b: &mut Vec<&'a Info>, i: &'a Info) { fn chain<'a>(b: &mut Vec<&'a Info>, i: &'a Info) {
b.push(i); b.push(i);
if let Some(ref r) = i.redirect { if let Some(ref r) = i.redirect {
chain(b, &r.info) chain(b, &r.referrer)
} }
} }
// Collect redirections into the buffer, // Collect redirections into the buffer,

View file

@ -5,11 +5,27 @@ use super::Info;
/// Unified redirection info wrapper for the application page /// Unified redirection info wrapper for the application page
pub struct Redirect { pub struct Redirect {
pub info: Info, pub referrer: Box<Info>,
pub method: Method, pub method: Method,
} }
impl Redirect { impl Redirect {
// Constructors
pub fn permanent(referrer: Info) -> Self {
Self {
referrer: Box::new(referrer),
method: Method::Permanent,
}
}
pub fn temporary(referrer: Info) -> Self {
Self {
referrer: Box::new(referrer),
method: Method::Temporary,
}
}
// Getters // Getters
/// Check redirection has external target /// Check redirection has external target
@ -21,6 +37,6 @@ impl Redirect {
.ok()? .ok()?
.host() .host()
} }
Some(parse(&self.info)? != parse(cmp)?) Some(parse(&self.referrer)? != parse(cmp)?)
} }
} }