mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +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>,
|
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
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
|
||||||
|
|
@ -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)?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue