mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 01:25:27 +00:00
implement 30,31 status codes
This commit is contained in:
parent
9f2d9ce110
commit
9818b3a998
4 changed files with 138 additions and 115 deletions
|
|
@ -1,7 +1,7 @@
|
|||
mod redirect;
|
||||
use redirect::Redirect;
|
||||
|
||||
use gtk::glib::{GString, Uri};
|
||||
use gtk::glib::GString;
|
||||
use std::{cell::RefCell, sync::Arc};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -27,6 +27,7 @@ pub struct Meta {
|
|||
status: RefCell<Status>,
|
||||
title: RefCell<GString>,
|
||||
redirect: RefCell<Option<Redirect>>,
|
||||
redirect_count: RefCell<i8>,
|
||||
}
|
||||
|
||||
impl Meta {
|
||||
|
|
@ -37,6 +38,7 @@ impl Meta {
|
|||
status: RefCell::new(status),
|
||||
title: RefCell::new(title),
|
||||
redirect: RefCell::new(None),
|
||||
redirect_count: RefCell::new(0),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -52,16 +54,22 @@ impl Meta {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn set_redirect(&self, count: i8, is_follow: bool, target: Uri) -> &Self {
|
||||
pub fn set_redirect(&self, request: GString, is_foreground: bool) -> &Self {
|
||||
self.redirect
|
||||
.replace(Some(Redirect::new(count, is_follow, target)));
|
||||
.replace(Some(Redirect::new(request, is_foreground)));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_redirect_count(&self, redirect_count: i8) -> &Self {
|
||||
self.redirect_count.replace(redirect_count);
|
||||
self
|
||||
}
|
||||
|
||||
/* @TODO not in use
|
||||
pub fn unset_redirect(&self) -> &Self {
|
||||
self.redirect.replace(None);
|
||||
self
|
||||
}
|
||||
} */
|
||||
|
||||
// Getters
|
||||
|
||||
|
|
@ -73,28 +81,14 @@ impl Meta {
|
|||
self.title.borrow().clone()
|
||||
}
|
||||
|
||||
pub fn is_redirect(&self) -> bool {
|
||||
self.redirect.borrow().is_some()
|
||||
pub fn redirect_count(&self) -> i8 {
|
||||
self.redirect_count.borrow().clone()
|
||||
}
|
||||
|
||||
pub fn redirect_count(&self) -> Option<i8> {
|
||||
match *self.redirect.borrow() {
|
||||
Some(ref redirect) => Some(redirect.count().clone()),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn redirect_target(&self) -> Option<Uri> {
|
||||
match *self.redirect.borrow() {
|
||||
Some(ref redirect) => Some(redirect.target().clone()),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn redirect_is_follow(&self) -> Option<bool> {
|
||||
match *self.redirect.borrow() {
|
||||
Some(ref redirect) => Some(redirect.is_follow().clone()),
|
||||
None => None,
|
||||
}
|
||||
/// WARNING!
|
||||
///
|
||||
/// This function **take** the `Redirect` without clone semantics
|
||||
pub fn take_redirect(&self) -> Option<Redirect> {
|
||||
self.redirect.take()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use gtk::glib::Uri;
|
||||
use gtk::glib::GString;
|
||||
|
||||
/// # Redirection data holder
|
||||
///
|
||||
|
|
@ -8,33 +8,32 @@ use gtk::glib::Uri;
|
|||
///
|
||||
/// ## Members
|
||||
///
|
||||
/// * `count` - to limit redirect attempts
|
||||
/// * `is_follow` - indicates how to process this redirect exactly
|
||||
/// * `target` - destination address
|
||||
/// * `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
|
||||
pub struct Redirect {
|
||||
count: i8,
|
||||
is_follow: bool,
|
||||
target: Uri,
|
||||
is_foreground: bool,
|
||||
request: GString,
|
||||
}
|
||||
|
||||
impl Redirect {
|
||||
pub fn new(count: i8, is_follow: bool, target: Uri) -> Self {
|
||||
// Constructors
|
||||
|
||||
pub fn new(request: GString, is_foreground: bool) -> Self {
|
||||
Self {
|
||||
count,
|
||||
is_follow,
|
||||
target,
|
||||
is_foreground,
|
||||
request,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn count(&self) -> &i8 {
|
||||
&self.count
|
||||
// Getters
|
||||
|
||||
pub fn request(&self) -> GString {
|
||||
self.request.clone()
|
||||
}
|
||||
|
||||
pub fn is_follow(&self) -> &bool {
|
||||
&self.is_follow
|
||||
}
|
||||
|
||||
pub fn target(&self) -> &Uri {
|
||||
&self.target
|
||||
pub fn is_foreground(&self) -> bool {
|
||||
self.is_foreground
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue