mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 08:35:28 +00:00
reorganize redirection Box
This commit is contained in:
parent
f2fb3c36ba
commit
e3477d2056
3 changed files with 25 additions and 13 deletions
|
|
@ -23,7 +23,7 @@ pub struct Info {
|
|||
mime: Option<String>,
|
||||
/// Hold redirections chain with handled details
|
||||
/// * 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
|
||||
request: Option<String>,
|
||||
/// Hold size info
|
||||
|
|
@ -49,20 +49,16 @@ impl Info {
|
|||
}
|
||||
}
|
||||
|
||||
/// Take `Self`, convert it into the new `Redirect` member,
|
||||
/// * return new `Self` that contain referring node
|
||||
fn into_redirect(self, method: redirect::Method) -> Self {
|
||||
pub fn into_permanent_redirect(self) -> Self {
|
||||
let mut this = Self::new();
|
||||
this.redirect = Some(Box::new(Redirect { info: self, method }));
|
||||
this.redirect = Some(Redirect::permanent(self));
|
||||
this
|
||||
}
|
||||
|
||||
pub fn into_permanent_redirect(self) -> Self {
|
||||
self.into_redirect(redirect::Method::Permanent)
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ impl Dialog for PreferencesDialog {
|
|||
fn chain<'a>(b: &mut Vec<&'a Info>, i: &'a Info) {
|
||||
b.push(i);
|
||||
if let Some(ref r) = i.redirect {
|
||||
chain(b, &r.info)
|
||||
chain(b, &r.referrer)
|
||||
}
|
||||
}
|
||||
// Collect redirections into the buffer,
|
||||
|
|
|
|||
|
|
@ -5,11 +5,27 @@ use super::Info;
|
|||
|
||||
/// Unified redirection info wrapper for the application page
|
||||
pub struct Redirect {
|
||||
pub info: Info,
|
||||
pub referrer: Box<Info>,
|
||||
pub method: Method,
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
/// Check redirection has external target
|
||||
|
|
@ -21,6 +37,6 @@ impl Redirect {
|
|||
.ok()?
|
||||
.host()
|
||||
}
|
||||
Some(parse(&self.info)? != parse(cmp)?)
|
||||
Some(parse(&self.referrer)? != parse(cmp)?)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue