From 29fee89e643d69a9a3f464ab2ac9a1c2b7c6e10e Mon Sep 17 00:00:00 2001 From: yggverse Date: Fri, 17 Jan 2025 22:17:01 +0200 Subject: [PATCH] implement `Redirect` options enum --- src/app/browser/window/tab/item/page.rs | 31 +++++++------------ .../tab/item/page/client/driver/gemini.rs | 24 +++++++------- .../window/tab/item/page/client/response.rs | 8 ++--- .../tab/item/page/client/response/redirect.rs | 6 ++++ 4 files changed, 31 insertions(+), 38 deletions(-) create mode 100644 src/app/browser/window/tab/item/page/client/response/redirect.rs diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index 69bb3197..c750638d 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -194,7 +194,7 @@ impl Page { snap_history(&self.profile, &self.navigation, None); // @TODO } - use client::response::{Certificate, Failure, Input}; + use client::response::{Certificate, Failure, Input, Redirect}; use client::Response; self.client @@ -211,7 +211,7 @@ impl Page { let window_action = self.window_action.clone(); move |response| { match response { - Response::Certificate(certificate) => match certificate { + Response::Certificate(this) => match this { Certificate::Invalid { title: certificate_title, } @@ -233,7 +233,7 @@ impl Page { browser_action.update.activate(Some(&id)); } }, - Response::Failure(failure) => match failure { + Response::Failure(this) => match this { Failure::Status { message } | Failure::Error { message } => { // Update widget let status_page = content.to_status_failure(); @@ -259,7 +259,7 @@ impl Page { browser_action.update.activate(Some(&id)); } }, - Response::Input(response_input) => match response_input { + Response::Input(this) => match this { Input::Response { base, title: response_title, @@ -301,22 +301,13 @@ impl Page { browser_action.update.activate(Some(&id)); } }, - Response::Redirect { - referrer, - request, - is_foreground, - } => { - // Some clients may support foreground redirects - // e.g. status code `31` in Gemini protocol - if is_foreground { - navigation - .request - .widget - .entry - .set_text(&request.to_string()); - } - - // @TODO request_async + Response::Redirect(this) => match this { + Redirect::Background { source, target } => todo!(), // @TODO + Redirect::Foreground { source, target } => navigation + .request + .widget + .entry + .set_text(&target.to_string()) // @TODO } Response::TextGemini { base, source, is_source_request } => { let widget = if is_source_request { diff --git a/src/app/browser/window/tab/item/page/client/driver/gemini.rs b/src/app/browser/window/tab/item/page/client/driver/gemini.rs index ae0c29a3..f181687e 100644 --- a/src/app/browser/window/tab/item/page/client/driver/gemini.rs +++ b/src/app/browser/window/tab/item/page/client/driver/gemini.rs @@ -1,5 +1,5 @@ use super::{ - response::{Certificate, Failure, Input}, + response::{Certificate, Failure, Input, Redirect}, Profile, Response, }; use gtk::{ @@ -96,13 +96,12 @@ pub fn handle( // https://geminiprotocol.net/docs/protocol-specification.gmi#status-30-temporary-redirection Status::Redirect => callback(match response.meta.data { Some(data) => match Uri::parse_relative(&base, &data.value, UriFlags::NONE) { - Ok(request) => Response::Redirect { - referrer: base, - request, - is_foreground: false, - }, + Ok(target) => Response::Redirect(Redirect::Foreground { + source: base, + target, + }), Err(e) => Response::Failure(Failure::Error { - message: format!("Could not parse target address: {}", e.message()), + message: format!("Could not parse target address: {e}"), }), }, None => Response::Failure(Failure::Error { @@ -112,13 +111,12 @@ pub fn handle( // https://geminiprotocol.net/docs/protocol-specification.gmi#status-31-permanent-redirection Status::PermanentRedirect => callback(match response.meta.data { Some(data) => match Uri::parse_relative(&base, &data.value, UriFlags::NONE) { - Ok(request) => Response::Redirect { - referrer: base, - request, - is_foreground: true, - }, + Ok(target) => Response::Redirect(Redirect::Background { + source: base, + target, + }), Err(e) => Response::Failure(Failure::Error { - message: format!("Could not parse target address: {}", e.message()), + message: format!("Could not parse target address: {e}"), }), }, None => Response::Failure(Failure::Error { diff --git a/src/app/browser/window/tab/item/page/client/response.rs b/src/app/browser/window/tab/item/page/client/response.rs index 559b7e56..937615c5 100644 --- a/src/app/browser/window/tab/item/page/client/response.rs +++ b/src/app/browser/window/tab/item/page/client/response.rs @@ -1,11 +1,13 @@ pub mod certificate; pub mod failure; pub mod input; +pub mod redirect; // Local dependencies pub use certificate::Certificate; pub use failure::Failure; pub use input::Input; +pub use redirect::Redirect; // Global dependencies use gtk::{ @@ -28,11 +30,7 @@ pub enum Response { is_source_request: bool, }, Input(Input), - Redirect { - is_foreground: bool, - referrer: Uri, - request: Uri, - }, + Redirect(Redirect), Stream { base: Uri, mime: String, diff --git a/src/app/browser/window/tab/item/page/client/response/redirect.rs b/src/app/browser/window/tab/item/page/client/response/redirect.rs new file mode 100644 index 00000000..f8784703 --- /dev/null +++ b/src/app/browser/window/tab/item/page/client/response/redirect.rs @@ -0,0 +1,6 @@ +use gtk::glib::Uri; + +pub enum Redirect { + Foreground { source: Uri, target: Uri }, + Background { source: Uri, target: Uri }, +}