Browse Source

validate connection step

CPP-GTK4
yggverse 3 months ago
parent
commit
9a0e9d3f17
  1. 148
      src/app/browser/main/tab/page.cpp

148
src/app/browser/main/tab/page.cpp

@ -131,86 +131,100 @@ void Page::update()
), .25 ), .25
); );
GioSocketConnection_RefPtr = GioSocketClient_RefPtr->connect_to_uri_finish( try
result {
); GioSocketConnection_RefPtr = GioSocketClient_RefPtr->connect_to_uri_finish(
result
// Request );
const Glib::ustring request = pageNavbar->get_request_text() + "\r\n"; }
GioSocketConnection_RefPtr->get_output_stream()->write_async( catch (const Glib::Error & EXCEPTION)
request.data(), {
request.size(), set(
[this](const Glib::RefPtr<Gio::AsyncResult> & result) pageNavbar->get_request_host(),
{ EXCEPTION.what(), 1
set( );
pageNavbar->get_request_host(), }
Glib::ustring::sprintf(
_("request %s.."), // Connection established, begin request
pageNavbar->get_request_path().empty() ? pageNavbar->get_request_host() if (GioSocketConnection_RefPtr != nullptr)
: pageNavbar->get_request_path() {
), .5 const Glib::ustring request = pageNavbar->get_request_text() + "\r\n";
);
GioSocketConnection_RefPtr->get_output_stream()->write_async(
// Response request.data(),
GioSocketConnection_RefPtr->get_input_stream()->read_async( // | read_all_async request.size(),
buffer, [this](const Glib::RefPtr<Gio::AsyncResult> & result)
sizeof(buffer) - 1, {
[this](const Glib::RefPtr<Gio::AsyncResult> & result) set(
{ pageNavbar->get_request_host(),
set( Glib::ustring::sprintf(
pageNavbar->get_request_host(), _("request %s.."),
Glib::ustring::sprintf( pageNavbar->get_request_path().empty() ? pageNavbar->get_request_host()
_("reading %s.."), : pageNavbar->get_request_path()
pageNavbar->get_request_path().empty() ? pageNavbar->get_request_host() ), .5
: pageNavbar->get_request_path() );
), .75
); // Response
GioSocketConnection_RefPtr->get_input_stream()->read_async( // | read_all_async
buffer,
sizeof(buffer) - 1,
[this](const Glib::RefPtr<Gio::AsyncResult> & result)
{
set(
pageNavbar->get_request_host(),
Glib::ustring::sprintf(
_("reading %s.."),
pageNavbar->get_request_path().empty() ? pageNavbar->get_request_host()
: pageNavbar->get_request_path()
), .75
);
// Parse meta // Parse meta
auto meta = Glib::Regex::split_simple( auto meta = Glib::Regex::split_simple(
R"regex(^(\d+)?\s([\w]+\/[\w]+)?)regex", R"regex(^(\d+)?\s([\w]+\/[\w]+)?)regex",
buffer buffer
); );
// Route by status code // Route by status code
if (meta[1] == "20") if (meta[1] == "20")
{
// Route by mime type or path extension
if (meta[2] == "text/gemini" || Glib::str_has_suffix(pageNavbar->get_request_path(), ".gmi"))
{ {
pageContent->set_text_gemini( // Route by mime type or path extension
buffer // @TODO if (meta[2] == "text/gemini" || Glib::str_has_suffix(pageNavbar->get_request_path(), ".gmi"))
); {
pageContent->set_text_gemini(
buffer // @TODO
);
}
else
{
pageContent->set_text_plain(
_("MIME type not supported")
);
}
} }
else else
{ {
pageContent->set_text_plain( pageContent->set_text_plain(
_("MIME type not supported") _("Could not open page")
); );
} }
}
else GioSocketConnection_RefPtr->close();
{
pageContent->set_text_plain( set(
_("Could not open page") pageNavbar->get_request_host(), // @TODO title
pageNavbar->get_request_path().empty() ? pageNavbar->get_request_host()
: pageNavbar->get_request_path()
, 1
); );
} }
);
GioSocketConnection_RefPtr->close(); }
);
set( }
pageNavbar->get_request_host(), // @TODO title
pageNavbar->get_request_path().empty() ? pageNavbar->get_request_host()
: pageNavbar->get_request_path()
, 1
);
}
);
}
);
} }
); );
} }

Loading…
Cancel
Save