mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-02-05 16:04:15 +00:00
draft redirection features
This commit is contained in:
parent
c97648539f
commit
380ade924f
@ -302,11 +302,12 @@ impl Page {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Response::Redirect {
|
Response::Redirect {
|
||||||
|
referrer,
|
||||||
request,
|
request,
|
||||||
is_foreground,
|
is_foreground,
|
||||||
} => {
|
} => {
|
||||||
// Some protocols may support foreground redirects
|
// Some clients may support foreground redirects
|
||||||
// for example status code `31` in Gemini
|
// e.g. status code `31` in Gemini protocol
|
||||||
if is_foreground {
|
if is_foreground {
|
||||||
navigation
|
navigation
|
||||||
.request
|
.request
|
||||||
|
@ -4,7 +4,7 @@ use super::{
|
|||||||
};
|
};
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::Cancellable,
|
gio::Cancellable,
|
||||||
glib::{Priority, Uri},
|
glib::{Priority, Uri, UriFlags},
|
||||||
};
|
};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
@ -94,15 +94,37 @@ pub fn handle(
|
|||||||
} // @TODO handle `None`
|
} // @TODO handle `None`
|
||||||
}
|
}
|
||||||
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-30-temporary-redirection
|
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-30-temporary-redirection
|
||||||
Status::Redirect => callback(Response::Redirect {
|
Status::Redirect => callback(match response.meta.data {
|
||||||
request: base,
|
Some(data) => match Uri::parse_relative(&base, &data.value, UriFlags::NONE) {
|
||||||
|
Ok(request) => Response::Redirect {
|
||||||
|
referrer: base,
|
||||||
|
request,
|
||||||
is_foreground: false,
|
is_foreground: false,
|
||||||
|
},
|
||||||
|
Err(e) => Response::Failure(Failure::Error {
|
||||||
|
message: format!("Could not parse target address: {}", e.message()),
|
||||||
}),
|
}),
|
||||||
|
},
|
||||||
|
None => Response::Failure(Failure::Error {
|
||||||
|
message: "Target address not found".to_string(),
|
||||||
|
}),
|
||||||
|
}), // @TODO validate redirect count
|
||||||
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-31-permanent-redirection
|
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-31-permanent-redirection
|
||||||
Status::PermanentRedirect => callback(Response::Redirect {
|
Status::PermanentRedirect => callback(match response.meta.data {
|
||||||
request: base,
|
Some(data) => match Uri::parse_relative(&base, &data.value, UriFlags::NONE) {
|
||||||
|
Ok(request) => Response::Redirect {
|
||||||
|
referrer: base,
|
||||||
|
request,
|
||||||
is_foreground: true,
|
is_foreground: true,
|
||||||
|
},
|
||||||
|
Err(e) => Response::Failure(Failure::Error {
|
||||||
|
message: format!("Could not parse target address: {}", e.message()),
|
||||||
}),
|
}),
|
||||||
|
},
|
||||||
|
None => Response::Failure(Failure::Error {
|
||||||
|
message: "Target address not found".to_string(),
|
||||||
|
}),
|
||||||
|
}), // @TODO validate redirect count
|
||||||
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-60
|
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-60
|
||||||
Status::CertificateRequest => callback(Response::Certificate(Certificate::Request {
|
Status::CertificateRequest => callback(Response::Certificate(Certificate::Request {
|
||||||
title: match response.meta.data {
|
title: match response.meta.data {
|
||||||
|
@ -29,8 +29,9 @@ pub enum Response {
|
|||||||
},
|
},
|
||||||
Input(Input),
|
Input(Input),
|
||||||
Redirect {
|
Redirect {
|
||||||
request: Uri,
|
|
||||||
is_foreground: bool,
|
is_foreground: bool,
|
||||||
|
referrer: Uri,
|
||||||
|
request: Uri,
|
||||||
},
|
},
|
||||||
Stream {
|
Stream {
|
||||||
base: Uri,
|
base: Uri,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user