mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 09:05:27 +00:00
implement Redirect options enum
This commit is contained in:
parent
380ade924f
commit
29fee89e64
4 changed files with 31 additions and 38 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue