Skip to content

Commit e3477d2

Browse files
author
yggverse
committed
reorganize redirection Box
1 parent f2fb3c3 commit e3477d2

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

src/app/browser/window/tab/item/page/navigation/request/info.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub struct Info {
2323
mime: Option<String>,
2424
/// Hold redirections chain with handled details
2525
/// * the `referrer` member name is reserved for other protocols
26-
redirect: Option<Box<Redirect>>,
26+
redirect: Option<Redirect>,
2727
/// Key to relate data collected with the specific request
2828
request: Option<String>,
2929
/// Hold size info
@@ -49,20 +49,16 @@ impl Info {
4949
}
5050
}
5151

52-
/// Take `Self`, convert it into the new `Redirect` member,
53-
/// * return new `Self` that contain referring node
54-
fn into_redirect(self, method: redirect::Method) -> Self {
52+
pub fn into_permanent_redirect(self) -> Self {
5553
let mut this = Self::new();
56-
this.redirect = Some(Box::new(Redirect { info: self, method }));
54+
this.redirect = Some(Redirect::permanent(self));
5755
this
5856
}
5957

60-
pub fn into_permanent_redirect(self) -> Self {
61-
self.into_redirect(redirect::Method::Permanent)
62-
}
63-
6458
pub fn into_temporary_redirect(self) -> Self {
65-
self.into_redirect(redirect::Method::Temporary)
59+
let mut this = Self::new();
60+
this.redirect = Some(Redirect::temporary(self));
61+
this
6662
}
6763

6864
// Actions

src/app/browser/window/tab/item/page/navigation/request/info/dialog.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ impl Dialog for PreferencesDialog {
202202
fn chain<'a>(b: &mut Vec<&'a Info>, i: &'a Info) {
203203
b.push(i);
204204
if let Some(ref r) = i.redirect {
205-
chain(b, &r.info)
205+
chain(b, &r.referrer)
206206
}
207207
}
208208
// Collect redirections into the buffer,

src/app/browser/window/tab/item/page/navigation/request/info/redirect.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,27 @@ use super::Info;
55

66
/// Unified redirection info wrapper for the application page
77
pub struct Redirect {
8-
pub info: Info,
8+
pub referrer: Box<Info>,
99
pub method: Method,
1010
}
1111

1212
impl Redirect {
13+
// Constructors
14+
15+
pub fn permanent(referrer: Info) -> Self {
16+
Self {
17+
referrer: Box::new(referrer),
18+
method: Method::Permanent,
19+
}
20+
}
21+
22+
pub fn temporary(referrer: Info) -> Self {
23+
Self {
24+
referrer: Box::new(referrer),
25+
method: Method::Temporary,
26+
}
27+
}
28+
1329
// Getters
1430

1531
/// Check redirection has external target
@@ -21,6 +37,6 @@ impl Redirect {
2137
.ok()?
2238
.host()
2339
}
24-
Some(parse(&self.info)? != parse(cmp)?)
40+
Some(parse(&self.referrer)? != parse(cmp)?)
2541
}
2642
}

0 commit comments

Comments
 (0)