mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 17:15:28 +00:00
update ggemini api, optimize failure handle
This commit is contained in:
parent
898c6d407f
commit
02dfa3cb3c
1 changed files with 18 additions and 49 deletions
|
|
@ -1,8 +1,5 @@
|
||||||
use super::{Feature, Page};
|
use super::{Feature, Page};
|
||||||
use ggemini::client::connection::response::{
|
use ggemini::client::connection::response::{Input, Redirect, Success};
|
||||||
Failure, Input, Redirect, Success,
|
|
||||||
failure::{Permanent, Temporary},
|
|
||||||
};
|
|
||||||
use ggemini::{
|
use ggemini::{
|
||||||
client::{Client, Request, Response},
|
client::{Client, Request, Response},
|
||||||
gio::{file_output_stream, memory_input_stream},
|
gio::{file_output_stream, memory_input_stream},
|
||||||
|
|
@ -503,7 +500,7 @@ fn handle(
|
||||||
},
|
},
|
||||||
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-30-temporary-redirection
|
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-30-temporary-redirection
|
||||||
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-31-permanent-redirection
|
// https://geminiprotocol.net/docs/protocol-specification.gmi#status-31-permanent-redirection
|
||||||
Response::Redirect(r) => match r.uri(&uri) {
|
Response::Redirect(redirect) => match redirect.uri(&uri) {
|
||||||
Ok(target) => {
|
Ok(target) => {
|
||||||
// Increase client redirection counter
|
// Increase client redirection counter
|
||||||
let total = redirects.take() + 1;
|
let total = redirects.take() + 1;
|
||||||
|
|
@ -543,7 +540,7 @@ fn handle(
|
||||||
update_page_info(&page, EVENT_COMPLETED);
|
update_page_info(&page, EVENT_COMPLETED);
|
||||||
} else {
|
} else {
|
||||||
let t = target.to_string();
|
let t = target.to_string();
|
||||||
if matches!(r, Redirect::Permanent { .. }) {
|
if matches!(redirect, Redirect::Permanent { .. }) {
|
||||||
page.navigation.set_request(&t);
|
page.navigation.set_request(&t);
|
||||||
}
|
}
|
||||||
redirects.replace(total);
|
redirects.replace(total);
|
||||||
|
|
@ -569,67 +566,39 @@ fn handle(
|
||||||
update_page_info(&page, EVENT_COMPLETED);
|
update_page_info(&page, EVENT_COMPLETED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Response::Certificate(c) => {
|
Response::Certificate(certificate) => {
|
||||||
// update page information
|
// update page information
|
||||||
let mut i = page.navigation.request.info.borrow_mut();
|
let mut i = page.navigation.request.info.borrow_mut();
|
||||||
i
|
i
|
||||||
.add_event(EVENT_COMPLETED.to_string())
|
.add_event(EVENT_COMPLETED.to_string())
|
||||||
.set_size(Some(c.as_bytes().len()), None)
|
.set_size(Some(certificate.as_bytes().len()), None)
|
||||||
.unset_mime()
|
.unset_mime()
|
||||||
.commit();
|
.commit();
|
||||||
page.navigation.request.update_secondary_icon(&i);
|
page.navigation.request.update_secondary_icon(&i);
|
||||||
// update page content widget
|
// update page content widget
|
||||||
let s = page.content.to_status_identity();
|
let s = page.content.to_status_identity();
|
||||||
s.set_description(Some(c.message_or_default()));
|
s.set_description(Some(certificate.message_or_default()));
|
||||||
// update other page members
|
// update other page members
|
||||||
page.set_progress(0.0);
|
page.set_progress(0.0);
|
||||||
page.set_title(c.message_or_default());
|
page.set_title(certificate.message_or_default());
|
||||||
if is_snap_history {
|
if is_snap_history {
|
||||||
page.snap_history();
|
page.snap_history();
|
||||||
}
|
}
|
||||||
// reset previous redirections
|
// reset previous redirections
|
||||||
redirects.replace(0);
|
redirects.replace(0);
|
||||||
}
|
}
|
||||||
Response::Failure(failure) => match failure {
|
Response::Failure(failure) => {
|
||||||
Failure::Temporary(ref temporary) => match temporary {
|
let s = page.content.to_status_failure();
|
||||||
Temporary::CgiError { message } |
|
s.set_description(Some(failure.message_or_default()));
|
||||||
Temporary::Default { message } |
|
page.set_progress(0.0);
|
||||||
Temporary::ProxyError { message } |
|
page.set_title(&s.title());
|
||||||
Temporary::ServerUnavailable { message } |
|
if is_snap_history {
|
||||||
Temporary::SlowDown { message } => {
|
page.snap_history();
|
||||||
let s = page.content.to_status_failure();
|
|
||||||
s.set_description(Some(message.as_ref().unwrap_or(&temporary.to_string())));
|
|
||||||
page.set_progress(0.0);
|
|
||||||
page.set_title(&s.title());
|
|
||||||
if is_snap_history {
|
|
||||||
page.snap_history();
|
|
||||||
}
|
|
||||||
redirects.replace(0); // reset
|
|
||||||
update_page_info(&page, EVENT_COMPLETED);
|
|
||||||
if let Some(callback) = on_failure {
|
|
||||||
callback()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Failure::Permanent(ref permanent) => match permanent {
|
redirects.replace(0); // reset
|
||||||
Permanent::BadRequest { message } |
|
update_page_info(&page, EVENT_COMPLETED);
|
||||||
Permanent::Default { message } |
|
if let Some(callback) = on_failure {
|
||||||
Permanent::Gone { message } |
|
callback()
|
||||||
Permanent::NotFound { message } |
|
|
||||||
Permanent::ProxyRequestRefused { message } => {
|
|
||||||
let s = page.content.to_status_failure();
|
|
||||||
s.set_description(Some(message.as_ref().unwrap_or(&permanent.to_string())));
|
|
||||||
page.set_progress(0.0);
|
|
||||||
page.set_title(&s.title());
|
|
||||||
if is_snap_history {
|
|
||||||
page.snap_history();
|
|
||||||
}
|
|
||||||
redirects.replace(0); // reset
|
|
||||||
update_page_info(&page, EVENT_COMPLETED);
|
|
||||||
if let Some(callback) = on_failure {
|
|
||||||
callback()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue