mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-27 11:34:14 +00:00
implement Redirect
options enum
This commit is contained in:
parent
380ade924f
commit
29fee89e64
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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,
|
||||
|
@ -0,0 +1,6 @@
|
||||
use gtk::glib::Uri;
|
||||
|
||||
pub enum Redirect {
|
||||
Foreground { source: Uri, target: Uri },
|
||||
Background { source: Uri, target: Uri },
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user