keep all redirects chain, add referrer holder

This commit is contained in:
yggverse 2024-12-10 00:04:09 +02:00
parent ff3f064534
commit ae5399e68e
4 changed files with 58 additions and 74 deletions

View file

@ -1,4 +1,4 @@
use gtk::glib::{Uri, UriFlags};
use gtk::glib::{GString, Uri, UriFlags};
/// Request type for `Page` with optional value parsed
pub enum Request {
@ -12,7 +12,9 @@ impl Request {
// Constructors
/// Create new `Self` from `request` string
pub fn from(request: &str) -> Self {
/// * if some `referrer` given, make additional check in previous request
pub fn from(request: &str, referrer: Option<&GString>) -> Self {
// check in request
if let Some(postfix) = request.strip_prefix("source:") {
if let Ok(uri) = Uri::parse(postfix, UriFlags::NONE) {
return Self::Source(uri);
@ -25,10 +27,25 @@ impl Request {
}
}
// check in referrer @TODO tmp
if referrer.is_some_and(|this| this.starts_with("source:")) {
if let Ok(uri) = Uri::parse(request, UriFlags::NONE) {
return Self::Source(uri);
}
}
if referrer.is_some_and(|this| this.starts_with("download:")) {
if let Ok(uri) = Uri::parse(request, UriFlags::NONE) {
return Self::Download(uri);
}
}
// is default
if let Ok(uri) = Uri::parse(request, UriFlags::NONE) {
return Self::Default(uri);
}
// is search
Self::Search(request.to_string())
}
}