mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-29 20:44:25 +00:00
fix redirects processed update
This commit is contained in:
parent
ae5399e68e
commit
e27f977bcd
@ -164,12 +164,12 @@ impl Page {
|
|||||||
let id = self.id.clone();
|
let id = self.id.clone();
|
||||||
|
|
||||||
// Prevent infinitive redirection
|
// Prevent infinitive redirection
|
||||||
if self.meta.total_redirects() > DEFAULT_MAX_REDIRECT_COUNT {
|
if self.meta.redirects() > DEFAULT_MAX_REDIRECT_COUNT {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try redirect request
|
// Try redirect request
|
||||||
let request = if let Some(redirect) = self.meta.last_redirect() {
|
let request = if let Some(redirect) = self.meta.redirect() {
|
||||||
if redirect.is_foreground {
|
if redirect.is_foreground {
|
||||||
self.navigation
|
self.navigation
|
||||||
.request
|
.request
|
||||||
@ -762,7 +762,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.total_redirects() > 5 {
|
} else if meta.redirects() > 5 {
|
||||||
// Update meta
|
// Update meta
|
||||||
meta.set_status(Status::Failure)
|
meta.set_status(Status::Failure)
|
||||||
.set_title("Oops");
|
.set_title("Oops");
|
||||||
@ -778,7 +778,7 @@ impl Page {
|
|||||||
// Redirection value looks valid, create new redirect (stored in meta `Redirect` holder)
|
// Redirection value looks valid, create new redirect (stored in meta `Redirect` holder)
|
||||||
// then call page reload action to apply it by the parental controller
|
// then call page reload action to apply it by the parental controller
|
||||||
} else {
|
} else {
|
||||||
meta.set_redirect(
|
meta.add_redirect(
|
||||||
// skip query and fragment by protocol requirements
|
// skip query and fragment by protocol requirements
|
||||||
// @TODO review fragment specification
|
// @TODO review fragment specification
|
||||||
resolved_uri.to_string_partial(
|
resolved_uri.to_string_partial(
|
||||||
|
@ -5,7 +5,7 @@ use redirect::Redirect;
|
|||||||
|
|
||||||
use gtk::glib::GString;
|
use gtk::glib::GString;
|
||||||
use sqlite::Transaction;
|
use sqlite::Transaction;
|
||||||
use std::cell::RefCell;
|
use std::cell::{Cell, RefCell};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Status {
|
pub enum Status {
|
||||||
@ -57,15 +57,18 @@ impl Meta {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_redirect(
|
pub fn add_redirect(
|
||||||
&self,
|
&self,
|
||||||
request: GString,
|
request: GString,
|
||||||
referrer: Option<GString>,
|
referrer: Option<GString>,
|
||||||
is_foreground: bool,
|
is_foreground: bool,
|
||||||
) -> &Self {
|
) -> &Self {
|
||||||
self.redirect
|
self.redirect.borrow_mut().push(Redirect {
|
||||||
.borrow_mut()
|
request,
|
||||||
.push(Redirect::new(request, referrer, is_foreground));
|
referrer,
|
||||||
|
is_foreground,
|
||||||
|
is_processed: Cell::new(false),
|
||||||
|
});
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,12 +82,17 @@ impl Meta {
|
|||||||
self.title.borrow().clone()
|
self.title.borrow().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn total_redirects(&self) -> usize {
|
pub fn redirects(&self) -> usize {
|
||||||
self.redirect.borrow().len() + 1
|
self.redirect.borrow().len() + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn last_redirect(&self) -> Option<Redirect> {
|
pub fn redirect(&self) -> Option<Redirect> {
|
||||||
self.redirect.borrow().last().cloned()
|
if let Some(redirect) = self.redirect.borrow().last() {
|
||||||
|
if !redirect.is_processed.replace(true) {
|
||||||
|
return Some(redirect.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
|
@ -1,32 +1,10 @@
|
|||||||
use gtk::glib::GString;
|
use gtk::glib::GString;
|
||||||
|
use std::cell::Cell;
|
||||||
|
|
||||||
/// # Redirection data holder
|
|
||||||
///
|
|
||||||
/// This component does nothing,
|
|
||||||
/// but useful as the container for temporary redirection data
|
|
||||||
/// operated by external controller
|
|
||||||
///
|
|
||||||
/// ## Members
|
|
||||||
///
|
|
||||||
/// * `is_foreground` - indicates how to process this redirect
|
|
||||||
/// * `request` - destination
|
|
||||||
/// * currently, it's raw `GString` not [Uri](https://docs.gtk.org/glib/struct.Uri.html)
|
|
||||||
/// because of compatibility with request field as it could contain any other, not parsable values
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Redirect {
|
pub struct Redirect {
|
||||||
pub is_foreground: bool,
|
pub is_foreground: bool,
|
||||||
|
pub is_processed: Cell<bool>,
|
||||||
pub referrer: Option<GString>,
|
pub referrer: Option<GString>,
|
||||||
pub request: GString,
|
pub request: GString,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Redirect {
|
|
||||||
// Constructors
|
|
||||||
|
|
||||||
pub fn new(request: GString, referrer: Option<GString>, is_foreground: bool) -> Self {
|
|
||||||
Self {
|
|
||||||
is_foreground,
|
|
||||||
referrer,
|
|
||||||
request,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user