mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-28 20:14:13 +00:00
update redirection rule
This commit is contained in:
parent
137301200f
commit
37a0c8ff4d
@ -399,48 +399,46 @@ fn handle(
|
|||||||
Status::PermanentRedirect | Status::Redirect => {
|
Status::PermanentRedirect | Status::Redirect => {
|
||||||
// Expected target URL in response meta
|
// Expected target URL in response meta
|
||||||
match response.meta.data {
|
match response.meta.data {
|
||||||
Some(data) => {
|
Some(data) => match uri.parse_relative(data.as_str(), UriFlags::NONE) {
|
||||||
match uri.parse_relative(data.as_str(), UriFlags::NONE) {
|
Ok(target) => {
|
||||||
Ok(target) => {
|
let total = redirects.take() + 1;
|
||||||
let total = redirects.take() + 1;
|
|
||||||
|
|
||||||
// Validate total redirects by protocol specification
|
// Validate total redirects by protocol specification
|
||||||
if total > 5 {
|
if total > 5 {
|
||||||
|
let status = subject.page.content.to_status_failure();
|
||||||
|
status.set_description(Some("Redirection limit reached"));
|
||||||
|
subject.page.title.replace(status.title());
|
||||||
|
subject.page.navigation.request.widget.entry.set_progress_fraction(0.0);
|
||||||
|
subject.tab_page.set_loading(false);
|
||||||
|
redirects.replace(0); // reset
|
||||||
|
|
||||||
|
// Disallow external redirection
|
||||||
|
} else if "gemini" != target.scheme()
|
||||||
|
|| uri.port() != target.port()
|
||||||
|
|| uri.host() != target.host() {
|
||||||
let status = subject.page.content.to_status_failure();
|
let status = subject.page.content.to_status_failure();
|
||||||
status.set_description(Some("Redirection limit reached"));
|
status.set_description(Some("External redirects not allowed by protocol specification"));
|
||||||
subject.page.title.replace(status.title());
|
subject.page.title.replace(status.title());
|
||||||
subject.page.navigation.request.widget.entry.set_progress_fraction(0.0);
|
subject.page.navigation.request.widget.entry.set_progress_fraction(0.0);
|
||||||
subject.tab_page.set_loading(false);
|
subject.tab_page.set_loading(false);
|
||||||
redirects.replace(0); // reset
|
redirects.replace(0); // reset
|
||||||
|
// Valid
|
||||||
// Disallow external redirection
|
} else {
|
||||||
} else if uri.scheme() != target.scheme()
|
if matches!(response.meta.status, Status::PermanentRedirect) {
|
||||||
|| uri.port() != target.port()
|
subject.page.navigation
|
||||||
|| uri.host() != target.host() {
|
.request
|
||||||
let status = subject.page.content.to_status_failure();
|
.widget
|
||||||
status.set_description(Some("External redirects not allowed by protocol specification"));
|
.entry
|
||||||
subject.page.title.replace(status.title());
|
.set_text(&uri.to_string());
|
||||||
subject.page.navigation.request.widget.entry.set_progress_fraction(0.0);
|
|
||||||
subject.tab_page.set_loading(false);
|
|
||||||
redirects.replace(0); // reset
|
|
||||||
// Valid
|
|
||||||
} else {
|
|
||||||
if matches!(response.meta.status, Status::PermanentRedirect) {
|
|
||||||
subject.page.navigation
|
|
||||||
.request
|
|
||||||
.widget
|
|
||||||
.entry
|
|
||||||
.set_text(&uri.to_string());
|
|
||||||
}
|
|
||||||
redirects.replace(total);
|
|
||||||
subject.page.tab_action.load.activate(Some(&target.to_string()), false);
|
|
||||||
}
|
}
|
||||||
|
redirects.replace(total);
|
||||||
|
subject.page.tab_action.load.activate(Some(&target.to_string()), false);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
}
|
||||||
let status = subject.page.content.to_status_failure();
|
Err(e) => {
|
||||||
status.set_description(Some(&e.to_string()));
|
let status = subject.page.content.to_status_failure();
|
||||||
subject.page.title.replace(status.title());
|
status.set_description(Some(&e.to_string()));
|
||||||
}
|
subject.page.title.replace(status.title());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user