implement Redirect options enum

This commit is contained in:
yggverse 2025-01-17 22:17:01 +02:00
parent 380ade924f
commit 29fee89e64
4 changed files with 31 additions and 38 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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,

View File

@ -0,0 +1,6 @@
use gtk::glib::Uri;
pub enum Redirect {
Foreground { source: Uri, target: Uri },
Background { source: Uri, target: Uri },
}