Browse Source

make redirect_count optional

master
yggverse 1 month ago
parent
commit
c8fb59988d
  1. 27
      src/app/browser/window/tab/item/page.rs
  2. 15
      src/app/browser/window/tab/item/page/meta.rs

27
src/app/browser/window/tab/item/page.rs

@ -169,13 +169,20 @@ impl Page {
// Try **take** request value from Redirect holder first // Try **take** request value from Redirect holder first
let request = if let Some(redirect) = self.meta.take_redirect() { let request = if let Some(redirect) = self.meta.take_redirect() {
// Increase redirect counter // Update redirect counter
self.meta.set_redirect_count(self.meta.redirect_count() + 1); self.meta
.set_redirect_count(match self.meta.redirect_count() {
// Prevent infinitive redirection by global settings Some(value) => {
if self.meta.redirect_count() > DEFAULT_MAX_REDIRECT_COUNT { // Prevent infinitive redirection
todo!(); if value > DEFAULT_MAX_REDIRECT_COUNT {
} todo!()
}
// Increase
Some(value + 1)
}
// Set initial value
None => Some(1),
});
// Update navigation on redirect `is_foreground` // Update navigation on redirect `is_foreground`
if redirect.is_foreground() { if redirect.is_foreground() {
@ -198,8 +205,8 @@ impl Page {
None => self.navigation.history_add(value), None => self.navigation.history_add(value),
} }
// Reset redirect counter as value taken from user input // Reset redirect counter as request value taken from user input
self.meta.set_redirect_count(0); self.meta.unset_redirect_count();
// Return value from navigation entry // Return value from navigation entry
self.navigation.request_text() self.navigation.request_text()
@ -715,7 +722,7 @@ impl Page {
) )
); );
// Client MUST limit the number of redirects they follow to 5 (by protocol specification) // Client MUST limit the number of redirects they follow to 5 (by protocol specification)
} else if meta.redirect_count() >= 5 { } else if meta.redirect_count() > Some(5) {
// Update meta // Update meta
meta.set_status(Status::Failure) meta.set_status(Status::Failure)
.set_title(&"Oops"); .set_title(&"Oops");

15
src/app/browser/window/tab/item/page/meta.rs

@ -27,7 +27,7 @@ pub struct Meta {
status: RefCell<Status>, status: RefCell<Status>,
title: RefCell<GString>, title: RefCell<GString>,
redirect: RefCell<Option<Redirect>>, redirect: RefCell<Option<Redirect>>,
redirect_count: RefCell<i8>, redirect_count: RefCell<Option<i8>>,
} }
impl Meta { impl Meta {
@ -38,7 +38,7 @@ impl Meta {
status: RefCell::new(status), status: RefCell::new(status),
title: RefCell::new(title), title: RefCell::new(title),
redirect: RefCell::new(None), redirect: RefCell::new(None),
redirect_count: RefCell::new(0), redirect_count: RefCell::new(None),
}) })
} }
@ -60,11 +60,18 @@ impl Meta {
self self
} }
pub fn set_redirect_count(&self, redirect_count: i8) -> &Self { pub fn set_redirect_count(&self, redirect_count: Option<i8>) -> &Self {
self.redirect_count.replace(redirect_count); self.redirect_count.replace(redirect_count);
self self
} }
pub fn unset_redirect_count(&self) -> &Self {
if self.redirect_count.borrow().is_some() {
self.set_redirect_count(None);
}
self
}
/* @TODO not in use /* @TODO not in use
pub fn unset_redirect(&self) -> &Self { pub fn unset_redirect(&self) -> &Self {
self.redirect.replace(None); self.redirect.replace(None);
@ -81,7 +88,7 @@ impl Meta {
self.title.borrow().clone() self.title.borrow().clone()
} }
pub fn redirect_count(&self) -> i8 { pub fn redirect_count(&self) -> Option<i8> {
self.redirect_count.borrow().clone() self.redirect_count.borrow().clone()
} }

Loading…
Cancel
Save