From b867eb596fe8822875260619e7c8239fad7685da Mon Sep 17 00:00:00 2001 From: yggverse Date: Thu, 24 Oct 2024 15:39:54 +0300 Subject: [PATCH] use ByteBuffer::read_input_stream_async API --- src/app/browser/window/tab/item/page.rs | 47 ++++++++++++++----------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index f699cc65..c3dc9738 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -20,8 +20,8 @@ use gtk::{ Uri, UriFlags, }, prelude::{ - ActionExt, IOStreamExt, InputStreamExtManual, OutputStreamExtManual, SocketClientExt, - StaticVariantType, ToVariant, + ActionExt, IOStreamExt, OutputStreamExtManual, SocketClientExt, StaticVariantType, + ToVariant, }, Box, }; @@ -235,24 +235,30 @@ impl Page { action_update.activate(Some(&id)); - // Read response - connection.input_stream().read_all_async( - vec![0; 0xfffff], // 1Mb @TODO - Priority::DEFAULT, - Some(&cancellable.clone()), - move |i| match i { - Ok(i) => { - // Define local NS - use gemini::client::response::{ - header::{ - Mime as ResponseMime, - Status as ResponseStatus - }, - Response, - }; + // Define local NS + use gemini::client::{ + connection::input_stream::ByteBuffer, + response::{ + header::{ + Mime as ResponseMime, + Status as ResponseStatus + }, + Response, + } + }; + // Read response + ByteBuffer::new().read_input_stream_async( + connection.input_stream(), + cancellable.clone(), + Priority::DEFAULT, + None, + None, + move |i| { + match i { + Ok(buffer) => { match Response::from_utf8( - &i.0.to_vec(), + &buffer.to_utf8(), ) { Ok(response) => { // Format response @@ -447,11 +453,11 @@ impl Page { todo!("Error closing connection: {}", error.message()); } } - Err(error) => { + Err(_) => { // Define common data let status = Status::Failure; let title = gformat!("Oops"); - let description = gformat!("Failed to read response: {}", error.1.message()); + let description = gformat!("Failed to read response"); // Update widget content.set_status_failure(title.as_str(), description.as_str()); @@ -469,6 +475,7 @@ impl Page { todo!("Error closing response connection: {}", error.message()); } } + } }, ); }