draft redirection features

This commit is contained in:
yggverse 2025-01-17 08:57:46 +02:00
parent c97648539f
commit 380ade924f
3 changed files with 36 additions and 12 deletions

View File

@ -302,11 +302,12 @@ impl Page {
}
},
Response::Redirect {
referrer,
request,
is_foreground,
} => {
// Some protocols may support foreground redirects
// for example status code `31` in Gemini
// Some clients may support foreground redirects
// e.g. status code `31` in Gemini protocol
if is_foreground {
navigation
.request

View File

@ -4,7 +4,7 @@ use super::{
};
use gtk::{
gio::Cancellable,
glib::{Priority, Uri},
glib::{Priority, Uri, UriFlags},
};
use std::rc::Rc;
@ -94,15 +94,37 @@ pub fn handle(
} // @TODO handle `None`
}
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-30-temporary-redirection
Status::Redirect => callback(Response::Redirect {
request: base,
is_foreground: false,
}),
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,
},
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
Status::PermanentRedirect => callback(Response::Redirect {
request: base,
is_foreground: true,
}),
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,
},
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
Status::CertificateRequest => callback(Response::Certificate(Certificate::Request {
title: match response.meta.data {

View File

@ -29,8 +29,9 @@ pub enum Response {
},
Input(Input),
Redirect {
request: Uri,
is_foreground: bool,
referrer: Uri,
request: Uri,
},
Stream {
base: Uri,